global variable not passing to handler in a droplet

I have a script that I have written that works perfectly when run from Script Editor. For ease of use, I am trying to convert it to a droplet.

When, I run it as a droplet, the script fails telling me that a variable doesn’t exist. The variable is most certainly defined as global, has a value attributed to it, and has been referenced in the main part of the script. It fails on the first occurrence in a handler.

Why would the global be passed when run as a script, but not as a droplet?


on open theItem

global personalization1List, personalization2List, personalization3List, personalization4List, personalization5List, vendorItemList, nr

tell application "Microsoft Excel"
		activate
		-- open the data file.
		set theData to theItem
		open theData
		set lastCell to first row index of (find column 2 what "" look in values look at whole)

		set vendorItemList to the value of the range ("ab2:ab" & (lastCell - 1))
		set personalization1List to the value of the range ("v2:v" & (lastCell - 1))
--.... blah blah blah... 
		close workbook 1 without saving
	end tell

set vendorItem to ""
	set personalization1 to ""
	set nr to ""

set vendorItem to item i of vendorItemList as string
		if vendorItem = "xxxx" then
--do lots of applescript things which I won't bore you with.
end

--the script gets to a handle call:
addLineItems(shipmentNumber, i)

---more stuff
end on

on addLineItems(shipmentID, x)
	tell application "FileMaker Pro Advanced"
		tell document "someDoc.fp7"
			
			tell table "thisTable"
				set nr to create new record at end
				tell nr
					set cell "FK_STshipment" to shipmentID
					set vendorItem to item x of vendorItemList as string
--The script fails on the above line saying that the vendorItemList is not defined.
--more stuff
end
end
end
end
end
end on addLineItems

Hi,

put the global declarations out of the on open handler.
Consider that the parameter of the on open handler is always list of alias specifiers


global personalization1List, personalization2List, personalization3List, personalization4List, personalization5List, vendorItemList, nr

on open theItems
	repeat with anItem in theItems
		tell application "Microsoft Excel"
			activate
			-- open the data file.
			set theData to anItem
			open theData
			set lastCell to first row index of (find column 2 what "" look in values look at whole)
			
			set vendorItemList to the value of the range ("ab2:ab" & (lastCell - 1))
			set personalization1List to the value of the range ("v2:v" & (lastCell - 1))
			--.... blah blah blah... 
			close workbook 1 without saving
		end tell
		
		set vendorItem to ""
		set personalization1 to ""
		set nr to ""
		
		set vendorItem to item i of vendorItemList as string
		if vendorItem = "xxxx" then
			--d o lots of applescript things which I won't bore you with. 
		end if
		
		--the script gets to a handle call:
		addLineItems(shipmentNumber, i)
		
		---more stuff
	end repeat
end open

on addLineItems(shipmentID, x)
	tell application "FileMaker Pro Advanced"
		tell document "someDoc.fp7"
			
			tell table "thisTable"
				set nr to create new record at end
				tell nr
					set cell "FK_STshipment" to shipmentID
					set vendorItem to item x of vendorItemList as string
					--The script fails on the above line saying that the vendorItemList is not defined.
					--more stuff
				end tell
			end tell
		end tell
	end tell
end addLineItems

Beautiful.

for some reason, I didn’t think the globals would be considered outside the on handler…

Thanks!

Oh. And, thanks for this tip. This will smooth things out for the end users, I am sure.