Building an object array based on Look Up Records Step
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2025 07:01 AM
Hello all,
I have a 'Look Up Records step' in a Flow Designer Action.Look Up Records step
I am attempting to iterate over the record set with a Script Step and build an object array.
Setting Record Set Varialbe
(function execute(inputs, outputs) {
try {
var conversationcontentarray = [];
var record_set = inputs.sys_cs_message_record_set;
// Directly iterate over the record set using an index-based approach
for (var i = 0; i < record_set.length; i++) {
var record = record_set[i];
// Build the conversationcontent object
var conversationcontent = {
one: record.sys_id,
two: 'text2', // Replace with actual field values from record
three: 'text3',
four: 'text4'
};
// Add to the result array
conversationcontentarray.push(conversationcontent);
}
// Output the constructed array
outputs.conversationcontentarray = conversationcontentarray;
} catch (error) {
gs.error("Error while building conversationcontent: " + error.stack);
}
})(inputs, outputs);
WHAT am I doing wrong!?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2025 07:37 AM
I hope your input type is of Reference to that Conversation Message table
You are passing complete array of objects?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2025 07:44 AM
Yeah,
I am getting record results in the Look Up Records Step.
Subflow results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2025 06:48 AM
so you are passing the complete array of objects?
Why not send individual object to that action?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2025 07:53 AM
Hi @lonesoac01 ,
Please try the below line of code while pushing into an Array. also use .toString() wherever you are dot walking.
Ex:
one: record.sys_id.toString()
conversationcontentarray.push(JSON.stringify(conversationcontent));
Please mark as correct/helpful! if this resolves your issue
Best Regards,
Pooja