The CreatorCon Call for Content is officially open! Get started here.

Need to map Payload field value to other fields

Anandak
Tera Contributor

Hi All, 

We have a string field "Payload" in Incident form with the below Json value and we want to map this payload values to different fields in a scope table. Please let me how we can map this details

  • Sample payload value -

{
"description":" test"
},
"test":{
" name":"service"
},
"test1":{
" name":"servicenow"
}

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Anandak 

you can parse the JSON and get the values and set

what script did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

rambo1
Tera Guru

Hi @Anandak 

Follow below sample code :

// The JSON payload provided
var jsonString = `{
"description": "test",
"test": {
"name": "service"
},
"test1": {
"name": "servicenow"
}
}`;

// Parse jsonString into a JavaScript object structure
var jsonObject = JSON.parse(jsonString);

// Create a new incident, and assign the JSON values to the incident's fields
var grIncident = new GlideRecord('incident');

grIncident.initialize();
grIncident.short_description = jsonObject.description;
grIncident.u_test = jsonObject.test.name;
grIncident.u_test1 = jsonObject.test1.name;

// Replace 'u_test' and 'u_test1' with the actual column names in your instance

grIncident.insert(); //