- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 04:23 AM
Hi
As discussed, I would like to update few fields based on incident state.
For example, the json will be different when the incident is 'New', and the json is different with different set of fields when it is 'On hold' and same as with 'Resolved'.
How can I add those state conditions here in the below code?
var InsertIncident = Class.create();
InsertIncident.prototype = {
initialize: function() {},
ProcessInsertIncident: function(requestData, response) {
var validJSON = this._checkJSONValidity(requestData);
var reqeustJSONParser = JSON.parse(validJSON);
var responseBody = {};
if (validJSON) {
var inc = new GlideRecord('incident');
inc.addQuery('correlation_id', reqeustJSONParser.id);
inc.query();
if (inc.next()) {
inc.caller_id = reqeustJSONParser.caller_id;
inc.short_description = reqeustJSONParser.short_description;
inc.description = reqeustJSONParser.description;
inc.work_notes = reqeustJSONParser.work_notes;
inc.category = reqeustJSONParser.category;
inc.update();
responseBody.Message = 'Incident is Updated';
} else {
inc.initialize();
inc.caller_id = reqeustJSONParser.caller_id;
inc.short_description = reqeustJSONParser.short_description;
inc.description = reqeustJSONParser.description;
inc.comments = reqeustJSONParser.comments;
inc.correlation_id = reqeustJSONParser.id;
inc.insert();
responseBody.Message = 'Incident is Created';
responseBody.Number = inc.number;
}
response.setBody(responseBody);
}
},
_checkJSONValidity: function(validJSON) {
try {
return JSON.stringify(validJSON);
} catch (e) {
gs.info('parsing error' + e);
}
},
type: 'InsertIncident'
};
could you please help me.
Thanks,
Priya.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 10:03 AM
for update i can see state:"${state}" which will work for update as your are accessing using below format
reqeustJSONParser.state="1"
But for create there is no state element in payload so you need to do like below by setting the state to "new" with out any conditions as it should be in new state while its getting created.
else {
var createInc =new GlideRecord('incident')
createInc.initialize();
createInc.caller_id = reqeustJSONParser.caller_id;
createInc.short_description = reqeustJSONParser.short_description;
createInc.description = reqeustJSONParser.description;
createInc.comments = reqeustJSONParser.comments;
createInc.correlation_id = reqeustJSONParser.id;
createInc.state="1";
createInc.insert();
responseBody.Message = 'Incident is Created';
responseBody.Number = createInc.number;
}
Please mark my answer correct if it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 07:57 AM
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 07:59 AM
happy to help !