# Whats up with runScript expressions?

**URL:** <https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [June 22, 2020, 5:13pm UTC](https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880 "2020-06-22T17:13:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![David.Reed.Schmidt](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@David.Reed.Schmidt](https://forum.inductiveautomation.com/u/David.Reed.Schmidt)\
**Post date:** [June 22, 2020, 5:13pm UTC](https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880/1 "2020-06-22T17:13:53Z")

</div>

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.

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

```

But when I put it in an expression tag like this

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/6/8630a1074e554075071b1d0166b45c86b25dc697.png)

The tag is bad and returns a value like this

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/2/c27d7f4850346f629667f4a54152e1e7adc93cc1.png)

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

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/1/41ebaa666d83190653ffbc9f293fe1daae93a945.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 22, 2020, 5:18pm UTC](https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880/2 "2020-06-22T17:18:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![David.Reed.Schmidt](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@David.Reed.Schmidt](https://forum.inductiveautomation.com/u/David.Reed.Schmidt)\
**Post date:** [June 22, 2020, 5:28pm UTC](https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880/3 "2020-06-22T17:28:25Z")

</div>

Unfortunatly its the same issue

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/1/c16bd8f0328dc27b1256dabe9197f1ee96efe81b.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 22, 2020, 5:58pm UTC](https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880/5 "2020-06-22T17:58:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![David.Reed.Schmidt](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@David.Reed.Schmidt](https://forum.inductiveautomation.com/u/David.Reed.Schmidt)\
**Post date:** [June 22, 2020, 11:06pm UTC](https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880/6 "2020-06-22T23:06:31Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 23, 2020, 1:02am UTC](https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880/7 "2020-06-23T01:02:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![David.Reed.Schmidt](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@David.Reed.Schmidt](https://forum.inductiveautomation.com/u/David.Reed.Schmidt)\
**Post date:** [June 23, 2020, 3:11pm UTC](https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880/8 "2020-06-23T15:11:57Z")

</div>

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:

```auto
#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.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/1/b196ffdbfea180d375f3976382efcaf19b324d38.png)

Here is the actual expression:

```auto
runScript('admin.shift.getShiftId')

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 23, 2020, 3:14pm UTC](https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880/9 "2020-06-23T15:14:28Z")

</div>

> [@paul-griffith](#):
>
> is the project where you’ve defined `admin.shift` set as the gateway scripting project?

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

---

<div class="post-metadata">

**Author:** ![David.Reed.Schmidt](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@David.Reed.Schmidt](https://forum.inductiveautomation.com/u/David.Reed.Schmidt)\
**Post date:** [June 23, 2020, 3:19pm UTC](https://forum.inductiveautomation.com/t/whats-up-with-runscript-expressions/35880/10 "2020-06-23T15:19:36Z")

</div>

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