# Script on Gateway giving error

**URL:** <https://forum.inductiveautomation.com/t/script-on-gateway-giving-error/76753>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [July 23, 2023, 3:58pm UTC](https://forum.inductiveautomation.com/t/script-on-gateway-giving-error/76753 "2023-07-23T15:58:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [July 23, 2023, 3:58pm UTC](https://forum.inductiveautomation.com/t/script-on-gateway-giving-error/76753/1 "2023-07-23T15:58:42Z")

</div>

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?

```auto
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])
		

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [July 23, 2023, 4:01pm UTC](https://forum.inductiveautomation.com/t/script-on-gateway-giving-error/76753/2 "2023-07-23T16:01:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [July 23, 2023, 7:31pm UTC](https://forum.inductiveautomation.com/t/script-on-gateway-giving-error/76753/3 "2023-07-23T19:31:14Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 23, 2023, 9:28pm UTC](https://forum.inductiveautomation.com/t/script-on-gateway-giving-error/76753/4 "2023-07-23T21:28:35Z")

</div>

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

```auto
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)

		

```

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [July 23, 2023, 9:41pm UTC](https://forum.inductiveautomation.com/t/script-on-gateway-giving-error/76753/5 "2023-07-23T21:41:57Z")

</div>

Thanks for that additional advice!
