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 temporary table records using parent array

AnilM99
Tera Expert

Hi Team,

my requirement is:

I am using rest message and get 3 arrays, and push 3 array to 1 parent array this is working good.

now my challenge is how to create temporary table records using parent array

example: 

var responsebody = [];

var response = [{"id":"c5864d0052db4ei0a481bbp0a1892fv8","name":"Test ServiceNow"}]

var response1 = [{"id":"d2454d0052db4ea0a481bbb0a2892fd5","name":"Test ServiceNow1"}]

var response2 = [{"id":"89d5d0052asjdi251bbb0a2asiome9axd3","name":"Test ServiceNow2"}]

 

responsebody.push(response);

responsebody.push(response1);

responsebody.push(response1);

 

now how to create temporary table record using "responsebody"

 

thanks

Anil

5 REPLIES 5

Subhashis Ratna
Tera Guru

HI @AnilM99 
Or you can optimize the code like this , 

var responseArray = [
    {"id":"c5864d0052db4ei0a481bbp0a1892fv8","name":"Test ServiceNow"},
    {"id":"d2454d0052db4ea0a481bbb0a2892fd5","name":"Test ServiceNow1"},
    {"id":"89d5d0052asjdi251bbb0a2asiome9axd3","name":"Test ServiceNow2"}
];
function createTemporaryRecord(data) {
    var tempRecord = new GlideRecord('your_temporary_table_name');
    tempRecord.initialize(); 
    tempRecord.setValue('field_name', data.name); 
    tempRecord.setValue('another_field_name', data.id); 
    tempRecord.insert(); 
}
for (var i = 0; i < responseArray.length; i++) {
    createTemporaryRecord(responseArray[i]);
}

 

SS : -

SubhashisRatna_0-1712745793741.png

 



If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

Thanks,
Subhashis Ratna