# Script Module

**URL:** <https://forum.inductiveautomation.com/t/script-module/3290>\
**Category:** Ignition\
**Created:** [September 16, 2011, 5:09pm UTC](https://forum.inductiveautomation.com/t/script-module/3290 "2011-09-16T17:09:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmoniz](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jmoniz](https://forum.inductiveautomation.com/u/jmoniz)\
**Post date:** [September 16, 2011, 5:09pm UTC](https://forum.inductiveautomation.com/t/script-module/3290/1 "2011-09-16T17:09:18Z")

</div>

I am trying to run a script module when I press a button. If i press the button I get the following error.

Traceback (innermost last):  
File “event:mouseClicked”, line 8, in ?  
ImportError: Error loading module scheduleCreate: null

Any ideas on what i have done wrong?

Thanks  
JP

################################################

Script Module Named scheduleCreate  
################################################

def create(LineNumber):  
import system, app

```
#the rest of the script
lineID = LineNumber

```

## 

## This script will run on sunday at midnight (00:00) and create all the scheduled runs for the (mon-sun) week.

## 

#get timestamp  
timestamp = system.db.runScalarQuery(“SELECT DATE\_FORMAT(NOW(), ‘%Y-%m-%d %H:%i:%s %w’)”)  
date = timestamp[:10]  
time = timestamp[-10:-5]  
day = int(timestamp[-1:]) #0=sunday, 6 = saturday

#######################################

Mouse Clicked Event on Button  
###################################

# This script was generated automatically by the property set

# script builder. You may modify this script, but if you do,

# you will not be able to use the property set builder to update

# this script without overwriting your changes.

# – ERROR – You must choose a destination property path.

LineNumber = event.source.Line  
app.scheduleCreate.create(LineNumber) -Line Number 8 in the script editior

####################################

---

<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:** [September 16, 2011, 5:28pm UTC](https://forum.inductiveautomation.com/t/script-module/3290/2 "2011-09-16T17:28:57Z")

</div>

Does your script module scheduleCreate compile ok? Do you only have one function called create? Can you copy and paste your code using the code block so we can see tabs?

---

<div class="post-metadata">

**Author:** ![jmoniz](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jmoniz](https://forum.inductiveautomation.com/u/jmoniz)\
**Post date:** [September 16, 2011, 5:31pm UTC](https://forum.inductiveautomation.com/t/script-module/3290/3 "2011-09-16T17:31:55Z")

</div>

Travis,

Yes it compiles with no errors.

[code]# This script was generated automatically by the property set

# script builder. You may modify this script, but if you do,

# you will not be able to use the property set builder to update

# this script without overwriting your changes.

# – ERROR – You must choose a destination property path.

LineNumber = event.source.Line  
app.scheduleCreate.create(LineNumber)[/code]

[code]def create(LineNumber):  
import system, app

```
#the rest of the script
lineID = LineNumber

```

## 

## This script will run on sunday at midnight (00:00) and create all the scheduled runs for the (mon-sun) week.

## 

#get timestamp  
timestamp = system.db.runScalarQuery(“SELECT DATE\_FORMAT(NOW(), ‘%Y-%m-%d %H:%i:%s %w’)”)  
date = timestamp[:10]  
time = timestamp[-10:-5]  
day = int(timestamp[-1:]) #0=sunday, 6 = saturday

#check if there is something on the schedule after now  
futureEvents = system.db.runScalarQuery(“SELECT COUNT(\*) FROM schedule WHERE FinishDateTime \> NOW() AND LineID == LineNumber”)  
print futureEvents

#check if it’s time to run  
if (day == 0 and time == “00:00”) or futureEvents == 0:

```
if lineID == 1:
	presetQuantity = 10
else:
	presetQuantity = 1

#insert 7 times, one for each day of the week
for i in range(7):
	#get the # of days to add to today
	result = system.db.runQuery("SELECT DATE_FORMAT('%s 00:00:00' + INTERVAL %s DAY, '%%Y-%%m-%%d'), DATE_FORMAT('%s 00:00:00' + INTERVAL %s DAY, '%%Y-%%m-%%d')" %(date, i, date, i+1))
	nextDay = result[0][0]
	dayAfter = result[0][1]
	#get shift start times
	shift1Start = system.db.dateFormat(system.tag.getTagValue("Shift 1 Start Time"), "HH:mm:ss")
	shift2Start = system.db.dateFormat(system.tag.getTagValue("Shift 2 Start Time"), "HH:mm:ss")
	shift3Start = system.db.dateFormat(system.tag.getTagValue("Shift 3 Start Time"), "HH:mm:ss")
	#one insert for each shift, the last one rolls over to the day after
	for i in range(3):
		if i == 0:
			startOfDay = "%s %s" %(nextDay, shift1Start)
			endOfDay = "%s %s" %(nextDay, shift2Start)
		elif i == 1:
			startOfDay = "%s %s" %(nextDay, shift2Start)
			endOfDay = "%s %s" %(nextDay, shift3Start)
		elif i == 2:
			startOfDay = "%s %s" %(nextDay, shift3Start)
			endOfDay = "%s %s" %(dayAfter, shift1Start)
		#insert
		system.db.runPrepUpdate("INSERT INTO schedule (LineID, WorkOrderID, ScheduleType, StartDateTime, FinishDateTime, Quantity, EnteredBy, RunStartDateTime, Timestamp, shift) VALUES (?, 1, 0, ?, ?, ?, 'System', ?, NOW(), ?)", [lineID, startOfDay, endOfDay, presetQuantity, startOfDay, i+1])
print "Schedules for 7 new Days created."[/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:** [September 16, 2011, 5:35pm UTC](https://forum.inductiveautomation.com/t/script-module/3290/4 "2011-09-16T17:35:14Z")

</div>

Make sure that all of the code is tabbed into the create function in your script module. It looks to me that the timestamp = … line is not part of the function which means system is not imported.

---

<div class="post-metadata">

**Author:** ![jmoniz](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jmoniz](https://forum.inductiveautomation.com/u/jmoniz)\
**Post date:** [September 16, 2011, 5:48pm UTC](https://forum.inductiveautomation.com/t/script-module/3290/5 "2011-09-16T17:48:11Z")

</div>

Thanks

That was it
