Building an object array based on Look Up Records Step

lonesoac01
Giga Guru

Hello all,

 

     I have a 'Look Up Records step' in a Flow Designer Action.Look Up Records stepLook Up Records step

I am attempting to iterate over the record set with a Script Step and build an object array.

Setting Record Set VarialbeSetting 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!?

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@lonesoac01 

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.

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

Yeah,

 

    I am getting record results in the Look Up Records Step.

 

Subflow resultsSubflow results

@lonesoac01 

so you are passing the complete array of objects?

Why not send individual object to that action?

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

Pooja58
Kilo Sage

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