Script error - onBefore script of Robust Transform Map

Priyanka Ghosh
Giga Guru

Hello,

 

I'm getting an error on the execution of the onBefore script of Transform map. What could be the probable reason and solution for this?

PFB the image of the code and the error:

 

PriyankaGhosh_0-1683230063163.png

PriyankaGhosh_1-1683230131194.png

 

5 REPLIES 5

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Priyanka Ghosh ,

 

I think the issue is with the Immediately Invoked function expression (line 105 - line 113), at line 113, you are passing the arguments as input & runID, since they are not defined anywhere, the javascript engine sets it to 'undefined' and hence the error message.

 

Please pass the actual array and sysID in line 113.

 

If my answer has helped with your qestion, please mark it as correct and helpful

 

Thanks!

Hello,

 

Line no.- 98-103 are the OOB comments provided by servicenow. So as per that input, runID, payload, length are all provided to this onBefore script by default. Is it not what those comments mean?

Yes, sorry - I ignored it
Can you log the payload variable and check its value?

asifnoor
Kilo Patron

Hi,

The error is in line no. 115. The payload seems to be a string and not a object. When you are trying to use payload.items.length, it is not able to parse this and hence you are getting an error. Check the value of payload and see that you are passing the object. Try to json.stringify and then json.parse in the function before using it.

 

Mark the comment as a correct answer and helpful if this has answered your question.