How add the JSON data in the fields?

sri83
Tera Guru

Hi Team,

 

As shown below, we receive JSON data from a third party system, and we need to store this data in a custom table.

I have created the import set table and mapping with target table. could you please suggest how to process the Applications [] array related data into the target table fields?

Thanks In advance

 

JSON Fomat:

 

{
"u_sys_id": "5f82c76f1b50e1106c1ab9118b4bcb55",
"u_state": "Ready",
"u_comments": "Sample comments",
"u_priority": "High",
"u_correlation_id": "TICKET123456789",
"applications": [
{
"name 1": "value 1",
"name 2": "value 2",
"name 3": "value 3",
"name 4": "value 4",
"name 5": "value 5"
}
]
}

1 ACCEPTED SOLUTION

sri83
Tera Guru

I have done achieved the requirement through Scripted REST Api. Thanks All!

View solution in original post

8 REPLIES 8

Ratnakar7
Mega Sage
Mega Sage

Hi @sri83 ,

 

To process the "applications" array related data into the target table fields, you can use a transform map in ServiceNow.

First, create a new transform map and select the import set table as the source table and the target table as the target table.

Next, map the fields in the target table to the corresponding fields in the import set table.

To map the fields in the "applications" array, you will need to create new fields in the target table for each of the "name" fields in the array. For example, if the "applications" array contains "name 1" through "name 5", you would create fields in the target table with the same names.

Then, for each of these fields, you can use a script to extract the corresponding value from the "applications" array. For example, to extract "value 1" from the first element of the "applications" array, you could use the following script:

 

var apps = source.u_applications;
if (apps && apps.length > 0) {
  target.u_name_1 = apps[0]['name 1'];
}

 

 

You would need to repeat this for each field in the "applications" array that you want to extract.

Finally, run the transform map to import the data from the import set table into the target table, and the data from the "applications" array should be correctly mapped to the new fields in the target table.

 

If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.

 

Thank you!

Ratnakar

Hi Ratnakar,

Thank you somuch for quick reply.

can you please confirm which method needs to use and achieve above requirement in the transform map

Please suggest.

 

When i am trying to hit the data from REST API Explorer application details are not storing in the table. Please fins the below screenshot.


 

sri83_1-1682311303030.png

 

sri83
Tera Guru

Hi Team,

Please help and give some suggestion to active this requirement.

 

Regards,

Sri

Ankur Bawiskar
Tera Patron
Tera Patron

@sri83 

why not use Scripted REST API?

In that parse the json and insert/update the target table records?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader