# runScript works in window expression but not email expression?

**URL:** <https://forum.inductiveautomation.com/t/runscript-works-in-window-expression-but-not-email-expression/77865>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [August 15, 2023, 1:38pm UTC](https://forum.inductiveautomation.com/t/runscript-works-in-window-expression-but-not-email-expression/77865 "2023-08-15T13:38:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 15, 2023, 1:38pm UTC](https://forum.inductiveautomation.com/t/runscript-works-in-window-expression-but-not-email-expression/77865/1 "2023-08-15T13:38:06Z")

</div>

Using 7.9.23.

I am tasked with making a report that gets emailed on a schedule per the report designer along with the feature that an admin can send one at any time manually.

To do this right I figured it was sensible to put the subject/body/filename calculations into functions so whether the scheduled report or admin is sending it manually, those things will be identical. My functions are simple -

```auto
def getSubject(endDateDT):
	return 'DPD Weeklies w/e %s'%(endDateDT)

def getBody():
	return "Colleagues,\n\nBelow are the project updates for the week.\n\nPlease feel free to reach out if you have any questions regarding the updates.\n\nThanks"

def getFileName(endDateDT):
	endDate = system.date.format(endDateDT, 'yyyy-MM-dd')
	return 'DPD Weeklies Updates %s.pdf'%(str(endDate))

```

However, even my simplest one does not work inside the report schedule designer -  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/c/3cc188dd931eb453e0699bdb94246970e351288b.png)

gives me  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/f/5f7d8235ba61a17ae907cbc2e5b5b2dfda33d788.png)

so then it sends me the actual text -  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/5/45c3d01922e4b0c0ed07a76bc7c23c9f5547f8ca.png)

My hunch is since the reports/emails are gateway level it's not looking at my project script (because `runScript('project.report.getBody')` does work as an expression binding of a text label) and so it cannot resolve my function name.

Anyone know what is going wrong here?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 15, 2023, 1:40pm UTC](https://forum.inductiveautomation.com/t/runscript-works-in-window-expression-but-not-email-expression/77865/2 "2023-08-15T13:40:03Z")

</div>

Probably needs to be in the `shared` script library to be accessed from a Gateway Scope. Probably also wouldn't work as an expression tag.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 15, 2023, 1:46pm UTC](https://forum.inductiveautomation.com/t/runscript-works-in-window-expression-but-not-email-expression/77865/3 "2023-08-15T13:46:56Z")

</div>

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

Unfortunately you're right still no luck even in a shared library.

I can hardcode it into these email parameters, it's just a pet peeve to have two sources of truth for me, one for if they send it manually via button press and another via the email scheduled.

It looks like I can probably leverage tags but I also don't like using them as intermediaries if I don't have to.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 15, 2023, 2:47pm UTC](https://forum.inductiveautomation.com/t/runscript-works-in-window-expression-but-not-email-expression/77865/4 "2023-08-15T14:47:22Z")

</div>

I don't see a zero polling value. `runScript()` might be waiting for a context that is never supplied.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 15, 2023, 4:30pm UTC](https://forum.inductiveautomation.com/t/runscript-works-in-window-expression-but-not-email-expression/77865/5 "2023-08-15T16:30:40Z")

</div>

Doesn't seem to matter. Docs say that argument is optional. With or without it, I still get the `WARN: Could not parse body text` and it sends what is in the box raw ie I get `runScript('shared.dpdresports.getBody()',0)` in my email body.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 15, 2023, 4:34pm UTC](https://forum.inductiveautomation.com/t/runscript-works-in-window-expression-but-not-email-expression/77865/6 "2023-08-15T16:34:42Z")

</div>

Huh. Maybe that body entry field is just broken. Have you tried other functions or tag references?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 15, 2023, 4:43pm UTC](https://forum.inductiveautomation.com/t/runscript-works-in-window-expression-but-not-email-expression/77865/7 "2023-08-15T16:43:37Z")

</div>

Tag seems to work fine, as does a concatting tag values with a string in the expression.

Ohh, very interesting. I just tried `runScript('system.date.now()'`) (with and without polling) in my body which works for a label text expression, but this too throws a `WARN: Could not parse body text`. Seems like this just does not work with or like runScript.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 15, 2023, 4:47pm UTC](https://forum.inductiveautomation.com/t/runscript-works-in-window-expression-but-not-email-expression/77865/8 "2023-08-15T16:47:38Z")

</div>

Try `objectScript()`, perhaps?
