- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 10:01 PM
I need to insert a record in Incident table through JSON format can anyone help to let it happen??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 10:30 PM
Hi @KM SN
if your JSON looks like: try background script
{
“short_description”: “Sample Incident”,
“urgency”: “2”,
“impact”: “2”,
“category”: “software”,
“subcategory”: “email”,
“assignment_group”: “287ebd7da9fe198100f92cc8d1d2154e”, // Example Sys ID of an Assignment Group
“assigned_to”: “9eecfbd7a9fe198100f92cc8d1d2154e” // Example Sys ID of a User
}
// Define the JSON string
var jsonData = '{"short_description":"Sample Incident","urgency":"2","impact":"2","category":"software","subcategory":"email","assignment_group":"287ebd7da9fe198100f92cc8d1d2154e","assigned_to":"9eecfbd7a9fe198100f92cc8d1d2154e"}';
// Parse the JSON string into an object
var dataObj = JSON.parse(jsonData);
// Create a new GlideRecord instance for the incident table
var gr = new GlideRecord('incident');
// Initialize a new record
gr.initialize();
// Assign values from the JSON object to the record
gr.short_description = dataObj.short_description;
gr.urgency = dataObj.urgency;
gr.impact = dataObj.impact;
gr.category = dataObj.category;
gr.subcategory = dataObj.subcategory;
if (dataObj.assignment_group) {
gr.assignment_group = dataObj.assignment_group;
}
if (dataObj.assigned_to) {
gr.assigned_to = dataObj.assigned_to;
}
// Insert the new record into the database
var newRecordSysId = gr.insert();
// Output the sys_id of the new record for confirmation
gs.info("New incident inserted with sys_id: " + newRecordSysId);
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 10:30 PM
Hi @KM SN
if your JSON looks like: try background script
{
“short_description”: “Sample Incident”,
“urgency”: “2”,
“impact”: “2”,
“category”: “software”,
“subcategory”: “email”,
“assignment_group”: “287ebd7da9fe198100f92cc8d1d2154e”, // Example Sys ID of an Assignment Group
“assigned_to”: “9eecfbd7a9fe198100f92cc8d1d2154e” // Example Sys ID of a User
}
// Define the JSON string
var jsonData = '{"short_description":"Sample Incident","urgency":"2","impact":"2","category":"software","subcategory":"email","assignment_group":"287ebd7da9fe198100f92cc8d1d2154e","assigned_to":"9eecfbd7a9fe198100f92cc8d1d2154e"}';
// Parse the JSON string into an object
var dataObj = JSON.parse(jsonData);
// Create a new GlideRecord instance for the incident table
var gr = new GlideRecord('incident');
// Initialize a new record
gr.initialize();
// Assign values from the JSON object to the record
gr.short_description = dataObj.short_description;
gr.urgency = dataObj.urgency;
gr.impact = dataObj.impact;
gr.category = dataObj.category;
gr.subcategory = dataObj.subcategory;
if (dataObj.assignment_group) {
gr.assignment_group = dataObj.assignment_group;
}
if (dataObj.assigned_to) {
gr.assigned_to = dataObj.assigned_to;
}
// Insert the new record into the database
var newRecordSysId = gr.insert();
// Output the sys_id of the new record for confirmation
gs.info("New incident inserted with sys_id: " + newRecordSysId);
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma