Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to create array in script step and use it in outputs

Shubham15
Kilo Contributor

I need to create an array using values from a custom table in script step and use its values as outputs for further flow. But I am not sure how to do so... I have tried to create an array but seems like it's not the right way. Can someone help me with it ?

Sample of what I created :-

(function execute(inputs, outputs) {
// ... code ...
var gr = new GlideRecord('x_797879_l_d_relea_create_product');
gr.query();
var short_description = gr.story_description;
var long_description = gr.story_long_description;
var array1 = new Array();
array1 = short_description.split(",");
var count1 = array1.length;
var array2 = long_description.split("STORY :");
var count2 = array2.length;
for(var i=0;i<count1;i++)
{
outputs.a[i] = array1[i];
outputs.b[i] = array2[i];
}

})(inputs, outputs); 

find_real_file.png

 

find_real_file.png

2 REPLIES 2

Martin iTSM
Tera Guru

Hi Shubam,

first thing is that you never do a "gr.next()" in your script, hence "gr" will not point to a record.

Example Script (not using inputs to keep it very simple):
-----
(function execute(inputs, outputs) {

var arrIncidents = new Array(); // Empty array we want to keep the incident numbers in

var grIncident = new GlideRecord('incident'); // GlideRecord to incident table
grIncident.setLimit(10); // Only 10 records
grIncident.query(); // query

while (grIncident.next()) { // Iterate through results
     arrIncidents.push(grIncident.number.toString()); // push number of each record into array
}

outputs.arrIncNumbers = arrIncidents; // set output variable to our populated array

})(inputs, outputs);
-----

You must assign the value of the step output variable to the output variable in the Outputs section of the action.

Result in TEST:
find_real_file.png


Hope this helps.

Martin

Can you elaborate first, what kind of array you are trying to create?