- 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:00 AM
did it work for the new record also with the above script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 07:21 AM
Hi
I have just removed the below condition from the script for create and it was working fine(creating incident in the target instance with New state).
if (reqeustJSONParser.state == '1')
Thank you for your help.
Just want to know how can we add multiple JSONs in the content field in HTTP method. like can we add create and update JSONs at the same time?
Thanks.
Priya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 07:23 AM
if it helped please close the thread by marking the answer correct so that it goes to solved queue and will help future readers
Good day!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 07:24 AM
Hi
Just want to know how can we add multiple JSONs in the content field in HTTP method. like can we add create and update JSONs at the same time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 07:26 AM
you need multiple JSON's ?