Get array from script include through query business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 12:58 AM
From a query business rule, we are calling a script include and returning a array of sysids through a function. I am unable to get that array in query business rule. Anyone please help me here.
@Ankur Bawiskar Please help us here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 01:25 AM
Hi @Nagasri
In Script Include return JSON.stringify(arr);
where arr is the array
In the BR use JSON.parse(arr);
Example :
SCRIPT INCLUDE
var Send_sys_id = Class.create();
Send_sys_id.prototype = {
initialize: function() {
},
send: function(){
var arr = ['12312','23e3e','32ed3ed32e'];
return JSON.stringify(arr);
},
type: 'Send_sys_id'
};
BUSINESS RULE
(function executeRule(current, previous /*null when async*/) {
var arr = new global.Send_sys_id().send();
arr = JSON.parse(arr);
gs.addInfoMessage(arr[2]);
})(current, previous);
Please let me know if this solves your QUERY.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 03:05 AM
Hi,
Can you please share what script you have written in script include and business rule?
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 10:29 PM
Things to check
1) BR and script include are in same scope?
2) Are you calling it in correct manner
Please share relevant scripts and screenshots of the BR and SI so that we can help
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader