Whats up with runScript expressions?

When I run the following script in the script console everything works fine. I think this is either a bug or there is a special trick that I’m not able to determine. For example, I have placed the expression tag in the same tag provider as the project that the script is associated with.

shiftId = admin.shift.getShiftId(1)
print shiftId

But when I put it in an expression tag like this

The tag is bad and returns a value like this

The current version of Ignition that we are running on the server is

image

If you’re using the ‘modern’ form of runscript (arguments as extra parameters to runScript) then your first argument should just be a reference to the calling function directly; no parentheses:
toInt(runScript('admin.shift.getShiftId', 1000, 1))

Unfortunatly its the same issue

Is your getShiftId interacting with other tags, or any databases? Since it’s being called from a gateway scope, there could be a number of issues - most likely something that relies on the project’s default database or default tag provider that’s not working since you’re outside of a particular project’s scope. Or even, is the project where you’ve defined admin.shift set as the gateway scripting project?

The getShiftId is exclusily scripting. Here it is and it is located in the global project.

#given shift scope will return the shift Id IAW the current timestamp
#shiftId = admin.shift.getShiftId(now)
def getShiftId(timestamp):

	#Day shift Id: 1
	#Swing shift Id: 2
	#Graveyard shift Id: 3
	
	if system.date.isBetween(timestamp, system.date.setTime(timestamp, 23, 30, 0), system.date.setTime(timestamp, 23, 59, 59)):
		return 3
	elif system.date.isBetween(timestamp, system.date.setTime(timestamp, 0, 0, 0), system.date.setTime(timestamp, 7, 29, 59)):
		return 3
	elif system.date.isBetween(timestamp, system.date.setTime(timestamp, 7, 30, 0), system.date.setTime(timestamp, 15, 29, 59)):
		return 1
	elif system.date.isBetween(timestamp, system.date.setTime(timestamp, 15, 30, 0), system.date.setTime(timestamp, 23, 29, 59)):
		return 2

Isn’t your function expecting a DateTime? You’re providing an integer, 1

2 Likes

Opps. When I was poking at the code I had changed it so you are right.

However I fixed it to correct code which is here:

#given shift scope will return the shift Id IAW the current timestamp
#shiftId = admin.shift.getShiftId()
def getShiftId():

	#Day shift Id: 1
	#Swing shift Id: 2
	#Graveyard shift Id: 3
	now = system.date.now()
	
	if system.date.isBetween(now, system.date.setTime(now, 23, 30, 0), system.date.setTime(now, 23, 59, 59)):
		return 3
	elif system.date.isBetween(now, system.date.setTime(now, 0, 0, 0), system.date.setTime(now, 7, 29, 59)):
		return 3
	elif system.date.isBetween(now, system.date.setTime(now, 7, 30, 0), system.date.setTime(now, 15, 29, 59)):
		return 1
	elif system.date.isBetween(now, system.date.setTime(now, 15, 30, 0), system.date.setTime(now, 23, 29, 59)):
		return 2

This will execute in the script console without issue. I’m running this in the global project that most of my projects inherit from. The global project has default as the tag provider. I created an expression tag in default tag provider and the tag is erred.

Here is the actual expression:

runScript('admin.shift.getShiftId')

Have you set the gateway scripting project, in Configure -> Gateway Settings?

1 Like

I updated the gateway scripting project and the script started to work. Thanks.

2 Likes