Sample Program 3
Description
This piece of code extracts the folder values for each selected item and then concatenates the folder value to the item text based on certain rules. It is highly recommended that this code be tested on an unimportant data file as the information will be written to the data file once you execute it cannot be undone.
Code
- id=get_select_items()
- max=table.maxn(id)
- for i=1,max do
- project=get_folder_value("Project",id[i])
- text=get_item_text(id[i])
- date=get_folder_value("Appointments",id[i])
- msgbox("Project "..project.."\n".."Item text "..text.."\n".."Date = "..date,"")
- if project~="" and string.sub(text,1,1)~="#" and date~="" then
- set_item_text(id[i],"#"..project.." "..text)
- end
- if project == "" and date~="" then
- msgbox("Item without project numbers","")
- end
- end
Code Explanation
- the item ids for all the selected items are collected in a table "id"
- the length of the table "id" is determined and saved as "max"
- for loop to loop through each of the selected items
- store the [Project] folder value in "project"
- store the ITT value in "text"
- store the [Appointments] folder value in date
- a message box that displays the stored values
- the first conditional that checks to see if project and date have value as well whether the initial character of the text equals "#"
- set the ITT with a new value based on the string "#"+project+text
- end of the first conditional
- This second conditional is a check on whether there the Project folder has no value and the appointment has value
- a message box displays the message that an item has no project number
- end of second conditional
- end of for loop