Store rest message response in to custom table

ABHINAV14
Tera Contributor

Below I having a rest message response which is in the Array format i think, i need to store the value of these three variable (handle, name and info ) to my custom table (xyz) which having three column u_handle, u_name and u_info

Please help me on that.

 [{"handle":"x0F123","name":"Attribute Leaders Group","info":"Attribute Leaders"},{"handle":"x0F00001562F65","name":"ART Active Safety Function Group","info":"Id = 400"},{"handle":"x0F000000006D2","name":"PSS360 Group","info":"ACTIVE SAFETY ELECTRONICS"},{"handle":"x0F000000015CB","name":"ART Common Base Technologies Group","info":"ID = 550"},{"handle":"x0F0000000F87","name":"ART AD and ADAS Platform Group","info":"Id = 420"},{"handle":"x0F000000011","name":"ART Core System Platform Group","info":"ID = 500"},{"handle":"x0F00000000555","name":"PSS110 Group","info":"ACTIVE SAFETY & VEHICLE DYNAMICS"},{"handle":"x0F0000000066","name":"ART Deceleration and Steering Group","info":"ID = 620"},{"handle":"x0F0000000077","name":"ART Exterior Systems Group","info":"ID = 730"},{"handle":"x0F0000000089","name":"ART Exterior Front and Rear Group","info":"ID = 700"}]

2 REPLIES 2

Alexandre Magea
Kilo Expert

Hi Abhinav,

What I think you should end up doing is to retrieve the string and to parse it as an object with JSON.parse().

So that's what you would do:

1) Retrieve the text you've shown using an API call

2) Parse the text (JSON) as an Array of objects with JSON.parse. You will then be able to manipulate the data as a regular JavaScript syntax (ex. element[0].handle)

3) Iterate through the element with a for loop and use GlideRecord to insert each of them in your table.

 

Let me know if you need more details.

Alexandre Mageau-Pétrin

 

Nikita Kale
Giga Guru

Hi

Try using the below script & let me know if it helps.

var arrStructure = [{"handle":"x0F123","name":"Attribute Leaders Group","info":"Attribute Leaders"},{"handle":"x0F00001562F65","name":"ART Active Safety Function Group","info":"Id = 400"},{"handle":"x0F000000006D2","name":"PSS360 Group","info":"ACTIVE SAFETY ELECTRONICS"},{"handle":"x0F000000015CB","name":"ART Common Base Technologies Group","info":"ID = 550"},{"handle":"x0F0000000F87","name":"ART AD and ADAS Platform Group","info":"Id = 420"},{"handle":"x0F000000011","name":"ART Core System Platform Group","info":"ID = 500"},{"handle":"x0F00000000555","name":"PSS110 Group","info":"ACTIVE SAFETY & VEHICLE DYNAMICS"},{"handle":"x0F0000000066","name":"ART Deceleration and Steering Group","info":"ID = 620"},{"handle":"x0F0000000077","name":"ART Exterior Systems Group","info":"ID = 730"},{"handle":"x0F0000000089","name":"ART Exterior Front and Rear Group","info":"ID = 700"}];


Object.keys(arrStructure).forEach(function(key) {
    var getKeys = arrStructure[key];
    var insertGR =new GlideRecord('xyz');
    insertGR.initialize();
    insertGR.u_handle = getKeys.handle; 
    insertGR.u_name = getKeys.name;
    insertGR.u_info = getKeys.info;
    insertGR.insert();

});

Thanks

Nikita