How to parse the rest message response and populate it on custom table?

rajkrish
Tera Contributor

Hi,

        I'm able to get back Json inputs from REST message

[ {"SiteName":"SC","LabName":"SVC","UnitNumber":"M5835JC800490","MaterialLotNumber":"L542C251","ProductName":"BROADWELL EP 24C","PartTypeName":"MF 8PTSFV A B","FullLocationName":"SHIP: CR3-1-C35 Mega Lab Inventory Control","QDFNumber":"","LastVPONumber":"","LastStepName":"","LastBinName":"","MirNumber":63362,"MirRequesterWWID":"10519277","MirRecipientWWID":"10552840"},

{"SiteName":"SC","LabName":"SVC","UnitNumber":"M5424BB700234","MaterialLotNumber":"L541C677","ProductName":"BROADWELL EP 24C","PartTypeName":"MF 8PTSFV A B","FullLocationName":"SHIP: CR3-1-C35 Mega Lab Inventory Control","QDFNumber":"","LastVPONumber":"","LastStepName":"","LastBinName":"","MirNumber":63362,"MirRequesterWWID":"10519277","MirRecipientWWID":"10552840"}]

I need to insert   these records into a custom table(lets say u_demo table). Kindly help me with a proper coding.

Thanks,

Rajkumar.

1 ACCEPTED SOLUTION

Hi Rajkumar,



      There is small changes in code which i had missed earlier.



      Try this latest modified code. Hope it will work!



      var r = new sn_ws.RESTMessageV2('REST_name_xxxx', 'get'); // in my case, we are using Get method


      var response = r.execute();


      var responseBody = response.getBody(); //fetches JSON response


      var response= JSON.parse(responseBody);



      for(i=0;i<response.length;i++)


        {


                            var gr = new GlideRecord('u_labname');


                          gr.initialize();


                        gr.u_fieldname = response[i].SiteName;


                          ....................


                        ...................


                      gr.insert();


        }



Thanks,


Kaka Nayeem




PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

10 REPLIES 10

Ajay Sharma2
Tera Guru

Hi,

 

Below code is working perfectly:


var r = new sn_ws.RESTMessageV2('Get data from other instance and update', 'Get name, id, company'); // in my case, we are using Get method

var response = r.execute();


var responseBody = response.getBody(); //fetches JSON response


var resp= JSON.parse(responseBody);


for(var i=0;i<resp.result.length;i++)


{

var gr = new GlideRecord('u_consume_data_from_sunil_dev');
gr.initialize();
gr.u_company = resp.result[i].company;
gr.u_id = resp.result[i].id;
gr.u_name = resp.result[i].name;
gr.insert();


}