Call script include from module argument not working

Ronak Jhaveri
Kilo Expert

Hi

I am calling script include from module arguments. Problem is, if i return hardcoded sys_id it works fine but when i write logic in script include it does not work.

Even if single gs.info() is written for logs without any other statement, it does not log the message.

Below is the screenshots.

find_real_file.png

 

 

5 REPLIES 5

Ronak Jhaveri
Kilo Expert

Adding screenshot of script include

find_real_file.png

Hello Ronak,

1. IN line number 12. make use of toString(). like below:

  x.push.(gr.location.sys_id.toString());

2.use gs.log instead gs.info as its working in scoped application

gs.info : Logs informational messages that describe the progress of the application. Setting the log level for an application to info generates info, warn, and error messages, but does not generate debug messages.


Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

Whenever you're looping and pushing data directly from a query, you need tostring() it.

array.push(gr.sys_id.toString); OR array.push(gr.getValue('sys_id').toString);

And see if that helps. Whatever is causing this problem I've seen it hundreds of times. If you're looping and you're using an object, if you don't string it you may end up with a list of the same thing (or worse- if you're doing an update on this field, you'll find yourself updating the same record numerous times). I always make sure to toString() or format the object so ServiceNow treats the data separately.


Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ronak,

can you use classless script include for this

i.e call it like this

^locationINjavascript:getLocationDetails

script include do this

function getLocationDetails(){

// your code

}

also while pushing into the array use toString()

x.push(gr.location.sys_id.toString());

return x.join(',');

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader