Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function createIncidentsFromJSON(payload) {
var data = JSON.parse(payload);
// Check if Data is Array or not, If not then add into array
var dataArray = Array.isArray(data) ? data : [data];


dataArray.forEach(function(item) {
var gr = new GlideRecord('incident');
gr.initialize();

for (var key in item) {
if (gr.isValidField(key)) {
gr[key] = item[key];
}
}
var incidentSysId = gr.insert();
gs.info("Incident created with Sys ID: " + incidentSysId);
});
}

// Usage with a single object
var singlePayload = '{"short_description":"System Down","caller_id":"durgesh1@example.com","priority":1,"assignment_group":"IT Support"}';
createIncidentsFromJSON(singlePayload);

// Usage with an array of objects
var arrayPayload = '[{"short_description":"System Down","caller_id":"durgesh2@example.com","priority":1,"assignment_group":"IT Support"}, {"short_description":"Email Issue","caller_id":"durgesh3@example.com","priority":2,"assignment_group":"IT Support"}]';
createIncidentsFromJSON(arrayPayload);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# JSON Mapping for Incident Creation

Usecase -

When we got the JSON payload (Object/Array of Object) for Incident creation with dynamic fields. You need a reusable script to create an Incident without hardcoding fields.
Loading