Get array from script include through query business rule

Nagasri
Tera Expert

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

3 REPLIES 3

piyushsain
Tera Guru
Tera Guru

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.

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Anil Lande
Kilo Patron

Hi,

Can you please share what script you have written in script include and business rule?

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Ankur Bawiskar
Tera Patron
Tera Patron

@Nagasri 

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

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