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.

Pull data from JSON array and save it into string field

chandukollapart
Tera Contributor

Hi,

We are doing integration to 3rd party system using web services and data will be getting in JSON format. I can pull data from each field but i have an JSON array from the list. So, i want to save the array data to string field in service now.

Data:

{

"ServiceTeam": null,

"Software": null,

"SoftwareVersion": null,

"Source": "MDS",

"IPAddresses": [

{

"Name": null,

"Number": "45231",

"Description": "Intel Ethernet Connection",

"IPAddress": "xx:xx:xx:xx:xx:xx"

},

{

"Name": null,

"Number": "45232",

"Description": "Async Adapter",

"IPAddress": "xx:xx:xx:xx:xx:xx"

},

{

"Name": null,

"Number": "45233",

"Description": "Intel Dual Band Wireless",

"IPAddress": "xx:xx:xx:xx:xx:xx"

}

]

},

In this above example i want to save the data from "IPAddresses": [ to end of an array in the string field. Any suggetions

Thanks

8 REPLIES 8

ariesmanlangit
Kilo Expert

Based on the Structure, the IPAddresses in the Data is an array of objects. You can try to access it by:






<Main object>.<sub object>[Index of data].<property>



Data.IPAddresses[0].Name


Data.IPAddresses[1].Name


Data.IPAddresses[2].Name






something like this.




Hope this helps.




a.c.manlangit


ServiceNow Developer Philippines




You may mark this as helpful or correct answer depending on the impact


HI Ariestotle,



I can save in the record to string field but i have issue with IPAddress value. Please see the attachment


Address1.JPG


how can we get the IPAddress value.



Thanks


I think this can be due to the character you used. the colon(':') in the ip address, your format is "xx:xx:xx:xx", it should be in "xx.xx.xx.xx", just a hunch.


Hi Ariestotle,




Tried the beolw thing and it works



var myData=



{


"ServiceTeam":null ,


"Software": null,


"SoftwareVersion":null ,


"Source": "MDS",


"IPAddresses":[]


}




Then inorder to push the data to IP Address use this :


myData.IPAddresses.push({


"Name": null,


"Number": "45231",


"Description": "Intel Ethernet Connection",


"IPAddress": "xx:xx:xx:xx:xx:xx"


});




myData.IPAddresses.push({


"Name": null,


"Number": "45232",


"Description": "Async Adapter",


"IPAddress": "xx:xx:xx:xx:xx:xx"


});




myData.IPAddresses.push({


"Name": null,


"Number": "45233",


"Description": "Intel Dual Band Wireless",


"IPAddress": "xx:xx:xx:xx:xx:xx"


});






post me your feedback


Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Have a lovely day ahead




Regards,


Divya Mishra