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

  1. id=get_select_items()
  2. max=table.maxn(id)
  3. for i=1,max do
  4. project=get_folder_value("Project",id[i])
  5. text=get_item_text(id[i])
  6. date=get_folder_value("Appointments",id[i])
  7. msgbox("Project "..project.."\n".."Item text "..text.."\n".."Date = "..date,"")
  8. if project~="" and string.sub(text,1,1)~="#" and date~="" then
  9. set_item_text(id[i],"#"..project.." "..text)
  10. end
  11. if project == "" and date~="" then
  12. msgbox("Item without project numbers","")
  13. end
  14. end

Code Explanation

  1. the item ids for all the selected items are collected in a table "id"
  2. the length of the table "id" is determined and saved as "max"
  3. for loop to loop through each of the selected items
  4. store the [Project] folder value in "project"
  5. store the ITT value in "text"
  6. store the [Appointments] folder value in date
  7. a message box that displays the stored values
  8. the first conditional that checks to see if project and date have value as well whether the initial character of the text equals "#"
  9. set the ITT with a new value based on the string "#"+project+text
  10. end of the first conditional
  11. This second conditional is a check on whether there the Project folder has no value and the appointment has value
  12. a message box displays the message that an item has no project number
  13. end of second conditional
  14. end of for loop