How to create array in script step and use it in outputs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 11:04 PM
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);
- Labels:
-
flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 04:44 AM
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:
Hope this helps.
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 05:02 AM
Can you elaborate first, what kind of array you are trying to create?