Script on Gateway giving error

Good day all,

This is a snippett of a bigger script. Can you tell me why I would be getting an error saying SuperName is not defined?

EndsDownRQD = system.tag.readBlocking(tagPathEndsDownRQD)[0].value
Line = i
tStamp = system.date.now()
Shift = system.tag.readBlocking("[default]Twisters/Current Shift")[0].value
	if Shift == "J":
		SuperName = "1-32 Carol Brookeshire, 33-65 Lind Smith"
	if Shift == "K":
		SuperName = "1-32 Andrew Frazier, 33-65 Tracy Presley"
	if Shift == "L":
		SuperName = "1-32 Sandra McIntyre, 33-65 Tim Foley"
	if Shift == "M":
		SuperName = "1-32 Juanita Gordon, 33-65 Jan Kelly"
#######ComponentNum
		
	system.db.runPrepUpdate("INSERT INTO Plt65_Twister_Production (tStamp, Line, Shift, RunTimeR, RunTimeL, LotNumR, LotNumL, BOCountRQD, BOCountRQC, BOCountR, BOCountLQB,BOCountLQA, BOCountL, MeterLenR, MeterLenL, TotShiftTimeR, TotShiftTimeL, DenierR, DenierL, LBSProdRQD, LBSProdRQC, LBSProdR, LBSProdLQB, LBSProdLQA, LBSProdL, MachineNum, EffRQD, EffRQC, EffR, EffLQB, EffLQA, EffL, DTperBreakRQD, DTperBreakRQC, DTperBreakR, DTperBreakLQB, DTperBreakLQA, DTperBreakL, DT, EndsDown, EndsDownLQA, EndsDownLQB, EndsDownRQC, EndsDownRQD, SuperName) Values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[tStamp, Line, Shift, RunTimeR, RunTimeL, LotNumR, LotNumL, BOCountRQD, BOCountRQC, BOCountR, BOCountLQB,BOCountLQA, BOCountL, MeterLenR, MeterLenL, TotShiftTimeR, TotShiftTimeL, DenierR, DenierL, LBSProdRQD, LBSProdRQC, LBSProdR, LBSProdLQB, LBSProdLQA, LBSProdL, MachineNum, EffRQD, EffRQC, EffR, EffLQB, EffLQA, EffL, DTperBreakRQD, DTperBreakRQC, DTperBreakR, DTperBreakLQB, DTperBreakLQA, DTperBreakL, DT, EndsDown, EndsDownLQA, EndsDownLQB, EndsDownRQC, EndsDownRQD, SuperName])
		

This is happening because none of your if conditions are evaluating as True, and SuperName is not defined outside of your if statements.

You're going to have to look at your current shift tag value, and figure out why it's not returning the expected J, K, L, or M.

3 Likes

Thank you sir. You were correct, for whatever reason it was returning "J[insert a lot of spaces here] ". So I just made it look for the first piece of the value like this:

Shift = system.tag.readBlocking("[default]Twisters/Current Shift")[0].value[0]

Stacked conditionals like this cause lots of problems as projects evolve. Consider moving to a cleaner implementation:

SuperNames = {
    "J": "1-32 Carol Brookeshire, 33-65 Lind Smith",
    "K": "1-32 Andrew Frazier, 33-65 Tracy Presley",
    "L": "1-32 Sandra McIntyre, 33-65 Tim Foley",
    "M": "1-32 Juanita Gordon, 33-65 Jan Kelly",
}
some_letter_designation = system.tag.readBlocking("[default]Twisters/Current Shift")[0].value
# from here, either assert the retrieved value is in the dictionary...
assert some_letter_designation in SuperNames.items(), "Invalid value!"
# or supply a helpful and actionable fallback value if the value is not found in the dictionary
SuperName = SuperNames.get(some_letter_designation, None)


		
1 Like

Thanks for that additional advice!