Inbound Action: "isNumeric" is not defined

Nia McCash
Mega Sage
Mega Sage

I tried creating a new Inbound Action for a custom task type that we have and the script seems to be giving some errors.

The script is as follows.   It is the same as the "Update Incident", "Update Problem", etc. scripts that came with ServiceNow originally:

gs.include('validators');

if (current.getTableName() == "my_custom_task_table_name") {

  current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;

  if (gs.hasRole("itil")) {

  if (email.body.assign != undefined)

  current.assigned_to = email.body.assign;

  if (email.body.priority != undefined && isNumeric(email.body.priority))

  current.priority = email.body.priority;

  }

  current.update();

}

Except I am seeing errors in the logs that say:

org.mozilla.javascript.EcmaError: "isNumeric" is not defined.

Caused by error in <refname> at line 1

==> 1: gs.include('validators');

2:

3: if (current.getTableName() == "my_custom_task_table_name") {

4: current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;

AND

org.mozilla.javascript.EcmaError: "isNumeric" is not defined.

Caused by error in Inbound Email Actions: 'Update Ad Hoc Request' at line 14

11: gs.warn("current.assigned_to = "+current.assigned_to, "Inbound debug") ;

12: }

13:

==> 14: if (email.body.priority != undefined && isNumeric(email.body.priority)) {

15: current.priority = email.body.priority;

16: gs.warn("current.priority = "+current.priority, "Inbound debug") ;

17: }

Where am I going wrong?   Why does the same script work just fine for Incident but not for my custom task type?

1 ACCEPTED SOLUTION

Nia McCash
Mega Sage
Mega Sage

My apologies to all who have been so helpful and patient... I'm not sure how to add a comment so that you're all notified but I just figured out the problem.   I completely forgot about the Application scope and am working in a different Application scope than Global.



validator script includes is only present in the Global application scope.



If I copy the validator script in my application scope and include the copy that I made, everything works as expected.


View solution in original post

21 REPLIES 21

aaronanderson
Kilo Expert

I've run into issues like this before when testing a pre-defined variable and it fails because there's no value coming in and you can't perform a isNumeric() on an undefined field.



Is it always failing? Or is it failing when that email tag doesn't exist?


I'm fairly new to ServiceNow and I'm actually not sure what is email.body.priority or where it comes from.



I notice that it consistently fails when the assigned_to user replies to the email sent to him/her that says something like



Subject: ADHOC0001230 has been assigned to you -- testing watch list



Nia,


Request ADHOC0001230 has been assigned to you.


Details of the Request:


State: Open


Priority: 4 - Low


Requested for: John Smith


Short Description: testing watch list


Issue Detail:


blah blah blah


To view the Request, click this LINK




Ref:MSG0002499



The email text is essentially the same for incident.   But when the assigned_to replies to the email above for incident, the email is processed without error.


email.body.priority is an email short tag. You can create variables from any text that is found in an email.



For instance, in your test copy/paste above if I created a tag: email.body.issue_detail



It would bring over blah blah blah if you had a colon in the original email. It basically looks at the email.body text and looks for the word(s) you have preceeding email.body. This means that email.body.priority is looking in the email for something that looks like:



Priority: text



To get back to the problem you're experiencing-- I've had this issue many times in email scripts, especially with fields that are defined outside of the script.



Since you're not defining what is inside the email.body.text_here , it will fail if you try to change the variable type. What you're trying to do is create a new variable by calling it email.body.text_here. If it doesn't find anything in the email, it's empty. Worse than that, it doesn't know what type of variable it is or anything about what it should contain. When you try to compare an unknown thing into an isNumeric, it gets confused.


In case you don't get updated when I updated my response above, this is just so you are aware I added a longer explanation.