Copy link to clipboard
Copied
Hi everyone,
The below my code read the text file from "".txt" file and store the values in txtinfo. And my requirement is if any one of the item or field is empty I need to alert the field name is missing.
The field names are contain with array of theList. I tried but getting only alert the missing item number and not able set the field name to missing item from theList array
Could anyone please help to fix this?
if myButton is equal to "Records" then
set txtInfo to my readVarsRetail(theFilePath)
set lnOnetxt to item 1 of txtInfo
set lnTwotxt to item 2 of txtInfo
set lnThreetxt to item 3 of txtInfo
set lnFourtxt to item 4 of txtInfo
set lnFivetxt to item 5 of txtInfo
set lnSixtxt to item 6 of txtInfo
set lnSeventxt to item 7 of txtInfo
set theList to {"description", "job_number", "languages", "dieline", "labels", "copy_editor", "creative_art_director"}
repeat with i from 1 to length of txtInfo
set emptyList to item i of txtInfo
if emptyList is equal to "" then
display dialog i
end if
end repeat
end if
I think you would be better off generating a string for the missing items. Something like this:
--the imported list
set textInfo to {"", "017849", "", "dieline", "", "Jon Doe", "Jane Doe"}
set theList to {"description", "job_number", "languages", "dieline", "labels", "copy_editor", "creative_art_director"}
set missing to ""
repeat with i from 1 to count of textInfo
if item i of textInfo is "" then
set missing to missing & item i of theList & return
end if
end repeat
display dialog "The
...
The string works better for the dialog display, but if you want the items stored in an array for use later in the script then this is how you would generate an array:
--the imported list
set textInfo to {"", "017849", "", "dieline", "", "Jon Doe", "Jane Doe"}
set theList to {"description", "job_number", "languages", "dieline", "labels", "copy_editor", "creative_art_director"}
set missing to {}
repeat with i from 1 to count of textInfo
if item i of textInfo is "" then
copy item i of the
...
Copy link to clipboard
Copied
Where’s the code for the readVarsRetail handler? Also you created the array theList but are not using it, are you trying to compare lists?
Copy link to clipboard
Copied
Sorry Roy! This was a big script. The text file contains 7 to 8 fields with value only. if any of the field is missing I need to alert compare with the theList and each item of txtInfo is match with below listed names.
set theList to {"description", "job_number", "languages", "dieline", "labels", "copy_editor", "creative_art_director"}
For Example,
if the item1 is missing and script need get the name from theList to alert "description field is missing" likewise if any one the field is missing the script will compare the any item of txtInfo with below names and to alert the missing field
Copy link to clipboard
Copied
if the item1 is missing and script need get the name from theList to alert "description field is missing"
Then I think for the dialog alert you would need:
display dialog "The " & item i of theList & " is missing"
For example if i = 4 you would get this:
Copy link to clipboard
Copied
Thank you so much for your help! Again I stuck, if more than two fields is missing but single alert will show for more fields also. I tried but it wont works. Could you help this out
set myListName to {}
repeat with i from 1 to length of txtInfo
set emptyList to item i of txtInfo
if emptyList is equal to "" then
set myemptyList to item i of theList
set myFinaList to myemptyList as string
set end of myListName to myFinaList
display dialog myListName
end if
end repeat
Copy link to clipboard
Copied
I cant able to push the missing fields into the array. The below error will get.
Copy link to clipboard
Copied
I think you would be better off generating a string for the missing items. Something like this:
--the imported list
set textInfo to {"", "017849", "", "dieline", "", "Jon Doe", "Jane Doe"}
set theList to {"description", "job_number", "languages", "dieline", "labels", "copy_editor", "creative_art_director"}
set missing to ""
repeat with i from 1 to count of textInfo
if item i of textInfo is "" then
set missing to missing & item i of theList & return
end if
end repeat
display dialog "These items are missing: " & return & missing
Copy link to clipboard
Copied
Thank you Rob! this is works fine for me.
Copy link to clipboard
Copied
The string works better for the dialog display, but if you want the items stored in an array for use later in the script then this is how you would generate an array:
--the imported list
set textInfo to {"", "017849", "", "dieline", "", "Jon Doe", "Jane Doe"}
set theList to {"description", "job_number", "languages", "dieline", "labels", "copy_editor", "creative_art_director"}
set missing to {}
repeat with i from 1 to count of textInfo
if item i of textInfo is "" then
copy item i of theList to end of missing
end if
end repeat
display dialog "The missing list: " & return & missing
An array as a string has no delimiters: