File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Server-Side Components/Script Includes/JSON Mapping for Incident Creation Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ function createIncidentsFromJSON ( payload ) {
2+ var data = JSON . parse ( payload ) ;
3+ // Check if Data is Array or not, If not then add into array
4+ var dataArray = Array . isArray ( data ) ? data : [ data ] ;
5+
6+
7+ dataArray . forEach ( function ( item ) {
8+ var gr = new GlideRecord ( 'incident' ) ;
9+ gr . initialize ( ) ;
10+
11+ for ( var key in item ) {
12+ if ( gr . isValidField ( key ) ) {
13+ gr [ key ] = item [ key ] ;
14+ }
15+ }
16+ var incidentSysId = gr . insert ( ) ;
17+ gs . info ( "Incident created with Sys ID: " + incidentSysId ) ;
18+ } ) ;
19+ }
20+
21+ // Usage with a single object
22+ var singlePayload = '{"short_description":"System Down","caller_id":"[email protected] ","priority":1,"assignment_group":"IT Support"}' ; 23+ createIncidentsFromJSON ( singlePayload ) ;
24+
25+ // Usage with an array of objects
26+ var arrayPayload = '[{"short_description":"System Down","caller_id":"[email protected] ","priority":1,"assignment_group":"IT Support"}, {"short_description":"Email Issue","caller_id":"[email protected] ","priority":2,"assignment_group":"IT Support"}]' ; 27+ createIncidentsFromJSON ( arrayPayload ) ;
Original file line number Diff line number Diff line change 1+ # JSON Mapping for Incident Creation
2+
3+ Usecase -
4+
5+ 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.
You can’t perform that action at this time.
0 commit comments