# SyntaxError: ("mismatched input 'SerialNo' expecting NEWLINE

**URL:** <https://forum.inductiveautomation.com/t/syntaxerror-mismatched-input-serialno-expecting-newline/7852>\
**Category:** Ignition\
**Created:** [January 16, 2014, 8:34pm UTC](https://forum.inductiveautomation.com/t/syntaxerror-mismatched-input-serialno-expecting-newline/7852 "2014-01-16T20:34:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccarruthers](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@ccarruthers](https://forum.inductiveautomation.com/u/ccarruthers)\
**Post date:** [January 16, 2014, 8:34pm UTC](https://forum.inductiveautomation.com/t/syntaxerror-mismatched-input-serialno-expecting-newline/7852/1 "2014-01-16T20:34:19Z")

</div>

I’m trying to add some error checking to a functioning script. The only thing new is the IF statement, which is throwing the following error:  
ERROR [ComponentScriptEditor-AWT-EventQueue-0] Parse error for event handler “actionPerformed”  
SyntaxError: (“mismatched input ‘SerialNo’ expecting NEWLINE”, (’’, 22, 3, ‘If SerialNo != 0:\n’))

Code is shown below. Any suggestions would be appreciated. Using Ignition 7.6.4.

Chris

YPartNo = system.tag.read(“AnvilInstall/YPartNo”).value  
SerialNo = system.tag.read(“AnvilInstall/SerialNo”).value  
CycleCount = system.db.runPrepQuery(“SELECT RunCount FROM PressEvent WHERE ID = ?”, [event.source.parent.PressEventID])  
CycleCount = CycleCount[0][0]

#Add a record to the Anvil table  
pk = system.db.runUpdateQuery(“INSERT INTO Anvil (YPartNo, SerialNo) VALUES (’%s’, %d)” % (YPartNo, SerialNo),getKey = 1)  
system.tag.write(“AnvilInstall/AnvilID”, pk)

# Add a record to the AnvilInstall table.

PressEventID = event.source.parent.PressEventID  
Position = event.source.parent.Position

If SerialNo != 0:  
system.db.runUpdateQuery(“INSERT INTO AnvilInstall (PressEventID, AnvilID, Position, PressCycles) VALUES (%d,%d,%d,%d)” % (PressEventID, pk, Position, CycleCount))  
#Update the AnvilID to its new value in the AnvilLoc table of the anvil being.  
system.db.runPrepUpdate(“UPDATE AnvilLoc SET AnvilID = ? Where Press = ? AND Position = ?”, [pk, event.source.parent.PressNo, event.source.parent.Position])  
# Clear values before next AnvilInstall data entered  
system.tag.write(“AnvilInstall/SerialNo”, “0”)  
# Close AnvilInstall window  
system.nav.closeParentWindow(event)  
Else:  
event.source.parent.getComponent(‘Label Error SerialNo’).visible = 1

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 16, 2014, 8:37pm UTC](https://forum.inductiveautomation.com/t/syntaxerror-mismatched-input-serialno-expecting-newline/7852/2 "2014-01-16T20:37:19Z")

</div>

‘If’ and ‘Else’ shouldn’t be capitalized.

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [January 16, 2014, 9:04pm UTC](https://forum.inductiveautomation.com/t/syntaxerror-mismatched-input-serialno-expecting-newline/7852/3 "2014-01-16T21:04:07Z")

</div>

You also have to make sure your code is properly indented:

[code]  
YPartNo = system.tag.read(“AnvilInstall/YPartNo”).value  
SerialNo = system.tag.read(“AnvilInstall/SerialNo”).value  
CycleCount = system.db.runPrepQuery(“SELECT RunCount FROM PressEvent WHERE ID = ?”, [event.source.parent.PressEventID])  
CycleCount = CycleCount[0][0]

#Add a record to the Anvil table  
pk = system.db.runUpdateQuery(“INSERT INTO Anvil (YPartNo, SerialNo) VALUES (’%s’, %d)” % (YPartNo, SerialNo),getKey = 1)  
system.tag.write(“AnvilInstall/AnvilID”, pk)

# Add a record to the AnvilInstall table.

PressEventID = event.source.parent.PressEventID  
Position = event.source.parent.Position

if SerialNo != 0:  
system.db.runUpdateQuery(“INSERT INTO AnvilInstall (PressEventID, AnvilID, Position, PressCycles) VALUES (%d,%d,%d,%d)” % (PressEventID, pk, Position, CycleCount))  
#Update the AnvilID to its new value in the AnvilLoc table of the anvil being.  
system.db.runPrepUpdate(“UPDATE AnvilLoc SET AnvilID = ? Where Press = ? AND Position = ?”, [pk, event.source.parent.PressNo, event.source.parent.Position])  
# Clear values before next AnvilInstall data entered  
system.tag.write(“AnvilInstall/SerialNo”, “0”)  
# Close AnvilInstall window  
system.nav.closeParentWindow(event)  
else:  
event.source.parent.getComponent(‘Label Error SerialNo’).visible = 1[/code]

---

<div class="post-metadata">

**Author:** ![ccarruthers](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@ccarruthers](https://forum.inductiveautomation.com/u/ccarruthers)\
**Post date:** [January 16, 2014, 9:47pm UTC](https://forum.inductiveautomation.com/t/syntaxerror-mismatched-input-serialno-expecting-newline/7852/4 "2014-01-16T21:47:23Z")

</div>

Thanks Kevin. Using lower case ‘if’ and ‘else’ did the trick
