Script Action utility node - why is my code not running? troubleshooting.

Michael Murphy
Tera Expert

Hi Everyone,  

I'm very new to VA and conversation flows so this probably sounds like a dumb question but I can't find out why my script action keeps throwing an error.

My original task was to call a custom script include that checks to see if a functionality pilot exists and then if the user is part of the pilot and returns either yes or no.  The script include works perfectly well all over the other parts of the system so the code in it is fine.  It is also available to all scopes but written in the global scope. (VA is in a scoped app).

I have tried all sorts but as soon as it gets to my script action step the error occurs.

So I created a new conversation flow in my PID with the code as just a single gs.log statement, thus eradicating any issues with any customisations my employers may have done on the system but when I test it throws an error.

I must be missing a fundamental step as there is no complex code in a log statement.  What am i missing?  take a look:

very simple flow:

find_real_file.png

code in script action:

find_real_file.png

test:

find_real_file.png

Log and the error message

find_real_file.png

the error seems to be this:  21:38:19.346: java.lang.RuntimeException: Script evaluation error at [topic__PRVW__79f272b287790110312c54f7940c2891_task_primary_field___silent_ScriptedAction_fe4e871a62cb45419fb6263ca20d3dd1_prompt_msg]: Error occurred when processing message com.glide.cs.qlue.module.runtime.expression.JSExpressionEvaluator.evaluate(JSExpressionEvaluator.java:58) com.glide.cs.qlue.module.taco.QuestionAnswerInteraction.getLabel(QuestionAnswerInteraction.java:1067)

 

It is probably something I have overlooked but I can't find a solution anywhere.  

regards,
Michael.

1 ACCEPTED SOLUTION

Michael Murphy
Tera Expert

Thanks Allen and Murali for your responses i finally managed to figure it out.

The key was when i discovered that gs.log() doesn't work in scoped apps! that was what was crashing the node and not letting me continue.  Allen was spot on.  Just logging with gs.info() did the trick.  i was able to log out all my statements to see where the code was falling down.

here are a few things i have learned that may be helpful for other newbies in future (this is on a Rome instance it may change):

  • gs.log() will break your code as it is only available in global scope see Logging for Scoped Applications — ServiceNow Elite
  • Any syntax errors or misspelling of table names / dot walking reference will stop your code running.
  • When calling a client script the syntax is: var myvar = new scriptIncludeName().functionInCS('prams'); not a split version where you instantiate the Script Include and then call the function - this breaks your code.
  • Contrary to the advice on the Test Virtual Agent guidance Test Virtual Agent topics | ServiceNow Docs  only gs.info() and gs.warn() logging works and they log to syslog table and not the log in the chatbot test window. 
  • gs.print() has the same effect as gs.log() and breaks your code.
  • You don't have to return anything from the function for it to move on. but follow the suggested syntax that is commented out when coding branching conditions.
  • The script action node will run code up to the line that breaks the flow so gs.info() generously to find the exact spot that is causing you problems.

 

If i had know these simple things it would have saved hours of frustrated googling.

Take her easy,
Murph.

View solution in original post

7 REPLIES 7

Allen Andreas
Administrator
Administrator

Hi,

It's recommended to use something like gs.info('message') instead.

I'm unsure of what your issue may actually be as you mentioned a script include, but then your script example is just logging. So is the logging AND script include not working?

When using the script include, did you use global.nameofSI().nameofFunc(), example?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

My original ask is to get the script include to fire but is was throwing the same error as above. so in debugging, to see why the script action was generating the error, i just went as basic as i could with a log statement.  
i have tried gs.info, gs.print, gs.log and gs.debug but the sequence never gets there. it takes a look at the block and just says no thanks. here's your meaningless error. off you go. bye bye.

Muralidharan BS
Mega Sage
Mega Sage

Hi,

It is not with your code, what do you have post the decision box? what is inside the "Always" and "End" components. That might be throwing you the error. 

VA will check for the next steps to execute and throws errors accordingly. 

Thanks

Hi Murali,

There is nothing in the other actions.  Nothing in the "always" branch, no code no condition and "end" is a simple text response to say end so i could tell it got to the end.

This should be one of the simplest functions of a VA designer flow to run some code to then base a decision on (which is my script include intent i mentioned before) but it won't run a simple hello world style log statement.

That's why i think there must be something missing.  don't know what it is though.