# Script block or call

**URL:** <https://forum.inductiveautomation.com/t/script-block-or-call/2955>\
**Category:** Ignition\
**Created:** [May 19, 2011, 4:31pm UTC](https://forum.inductiveautomation.com/t/script-block-or-call/2955 "2011-05-19T16:31:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jim\_lapratt](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jim\_lapratt](https://forum.inductiveautomation.com/u/jim_lapratt)\
**Post date:** [May 19, 2011, 4:31pm UTC](https://forum.inductiveautomation.com/t/script-block-or-call/2955/1 "2011-05-19T16:31:02Z")

</div>

Below is the script I have on a button. After all the checks to make sure things are as they should be and the query or query’s are performed I want to reset certain fields on the screen as you see at end. Is there a way to label that group and then call that label in the script so there is only one place things need changed? I hope that makes sense…

[code]IDEMP = event.source.parent.IDEMP  
IDLOCATION = event.source.parent.IDLOCATION  
IDMATERIAL = event.source.parent.IDMATERIAL  
IDTRANSTYPE = event.source.parent.IDTRANSTYPE  
QUANTITY = event.source.parent.getComponent(‘QTY Box’).intValue  
REASON = event.source.parent.getComponent(‘ReasonDropdown’).selectedValue  
COMPANY = event.source.parent.getComponent(‘CompanyDropdown’).selectedValue  
MACHINE = event.source.parent.getComponent(‘MachineDropdown’).selectedValue

# Query to insert a addition or hard count into inventory

QRY = “INSERT INTO tbl\_invtransactions (id\_employee, id\_invtranstype, id\_ourmaterial, id\_location, qty, date) VALUES (%d,%d,%d,%d,%d,CURRENT\_TIMESTAMP)” % (IDEMP, IDTRANSTYPE, IDMATERIAL, IDLOCATION, QUANTITY)

#print QRY

if event.source.parent.getComponent(‘TransTypeDropdown’).selectedStringValue == “Out”:  
if REASON != -1:  
print “step 1”  
if COMPANY != -1:  
print “Step 2”  
if MACHINE != -1:  
print “step 3”  
NEWID = system.db.runUpdateQuery (“INSERT INTO tbl\_invtransactions (id\_employee, id\_invtranstype, id\_ourmaterial, id\_location, qty, date) VALUES (%d,%d,%d,%d,%d,CURRENT\_TIMESTAMP)” % (IDEMP, IDTRANSTYPE, IDMATERIAL, IDLOCATION, QUANTITY), getKey=1)  
#print NEWID  
system.db.runUpdateQuery (“INSERT INTO tbl\_invtransdetails (id\_invtransaction, id\_invreason, id\_machine, id\_company) VALUES (%d,%d,%d,%d)” % (NEWID, REASON, MACHINE, COMPANY))  
#  
# Insert screen reset call here  
#  
else:  
#print “Bad Step 3”  
system.gui.messageBox(“Need to Select a Machine”)  
else:  
#print “Bad Step 2”  
system.gui.messageBox(“Need to Select a Company”)  
else:  
#print “Bad step 1”  
system.gui.messageBox(“Need to Select a Reason Code”)

# Do a inventory IN or a HARD COUNT

else:  
NEWID = system.db.runUpdateQuery (“INSERT INTO tbl\_invtransactions (id\_employee, id\_invtranstype, id\_ourmaterial, id\_location, qty, date) VALUES (%d,%d,%d,%d,%d,CURRENT\_TIMESTAMP)” % (IDEMP, IDTRANSTYPE, IDMATERIAL, IDLOCATION, QUANTITY), getKey=1)  
#print NEWID  
#  
# Insert screen reset call here  
#

# Reset these fields on screen for selection of next input

event.source.parent.getComponent(‘QTY Box’).intValue = 0  
event.source.parent.getComponent(‘Table 2’).selectedRow = -1  
event.source.parent.getComponent(‘Table 1’).selectedRow = -1  
event.source.parent.getComponent(‘LocationBox’).text =""  
event.source.parent.getComponent(‘LocationBox’).MyString = “”  
event.source.parent.getComponent(‘ReasonDropdown’).selectedValue = -1  
event.source.parent.getComponent(‘CompanyDropdown’).selectedValue = -1  
event.source.parent.getComponent(‘MachineDropdown’).selectedValue = -1

fpmi.db.refresh(event.source.parent.getComponent(“Table 2”),“data”)[/code]

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [May 19, 2011, 4:34pm UTC](https://forum.inductiveautomation.com/t/script-block-or-call/2955/2 "2011-05-19T16:34:04Z")

</div>

You do that by creating a function. Here is an example:[code]def doSomething(arg1, arg2, …):  
import system, app  
# your code  
return value # if you want to return a value

# more code

value = doSomething(val1, val2, …) # leave out value = if not returning a value  
#more code[/code]Hope that helps.

---

<div class="post-metadata">

**Author:** ![jim\_lapratt](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jim\_lapratt](https://forum.inductiveautomation.com/u/jim_lapratt)\
**Post date:** [May 19, 2011, 4:43pm UTC](https://forum.inductiveautomation.com/t/script-block-or-call/2955/3 "2011-05-19T16:43:46Z")

</div>

Travis,

Thanks I just found that in the book and was just getting ready to post that I think I may have it. If I break it I will be back here… Hehe
