Need to map Payload field value to other fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2025 09:55 AM
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"
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2025 07:42 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2025 07:47 PM
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(); //