Insert json to importset table

pratiksha5
Mega Sage

I am creating a data source using load by script option. I am able to retrive the data but not able to correctly put it in the import set table. 

 

The Json looks like this : 

 

{
"data": {
"type": "io",
"id": "123",
"attributes": {
"ipAddresses": [
"101.10.113.95"
],
"deviceName": "Device@101.10.113.95",
"deviceType": "unknown",
"makeModel": null,
 
},
"relationships": {
"tenant": {
"data": {
"type": "tenant",
"id": "123",
"attributes": {
"domainPrefix": "abc"
}
}
},
 
Code : 
var parsedResponse = JSON.parse(responseBody);
            var deviceData = parsedResponse.data;
 
 
            //Loop through each record and insert data into import set table
 
            for (var eachDevice in deviceData) {
var map ={
u_type: deviceData[eachDevice].type, //works fine
u_id:deviceData[eachDevice].id, //works fine
u_deviceName:deviceData[eachDevice]['attributes'].deviceName //not working
 
};           
I have tried multiple ways but not getting the values inserted in the import set. Please help 
@Ravi Chandra_K @AnkurBawiskar

1 ACCEPTED SOLUTION

Found the solution  u_attributes_devicename: deviceData[eachDevice]['attributes']['deviceName']

I have to write the name of the import set column name plus access the array in given format. 

View solution in original post

7 REPLIES 7

Mohith Devatte
Tera Sage
Tera Sage

Hello @pratiksha5 ,

i think you have to use this in order to access device name 

u_deviceName:deviceData[eachDevice].deviceName

 

As device name is a separate JSON element and its not coming under attributes  sub json you can directly access it like above and try 

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks

I think we need to access the attribute in order to access the array. I tried your way and it did not work. 

@pratiksha5 my bad did not observe the JSON structure properly .Can you try the below one 

u_deviceName:deviceData[eachDevice].attributes.deviceName

I have tried this and it is not working as well.