I have query on Scripted rest API PUT Method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:18 AM
Hello,
I want to update an incident using scripted rest API, PUT Method
here i want to update the following fields like
short_description, impact, urgency,assignment_group,category,subcategory,work note for this i have written one script include and that script include is called from scripted rest API,
Please find the below code:
script Include:
UpdateIncData: function(requestData) {
var resp = {};
var recordData = request.body.data.recordData || {};
var upInc = new GlideRecord('incident');
upIn.addQuery('sys_id', sys_id);
upIn.query();
if (upIn.next()) {
if (recordData.short_description)
upIn.setValue('short_description', recordData.short_description);
if (recordData.description)
upIn.setValue('description', recordData.description);
if (recordData.assignment_group)
upIn.setValue('assignment_group', recordData.assignment_group);
if (recordData.category)
upIn.setValue('category', recordData.category);
if (recordData.subcategory)
upIn.setValue('subcategory', recordData.subcategory);
upIn.update();
}
resp.message = "Record Updated Successfully";
resp.status = "200";
return resp;
},
type: 'Integration'
};
Scripted rest API Code :
var requestBody = request.body;
var requestData = requestBody.data;
var data ={};
var res;
response.setContentType('application/json');
var operationName = request.getHeader('operation');
if(operationName == 'update'){
data = new Integration().UpdateIncData(requestData);
}
//data.result = res.toString();
response = JSON.stringify(data);
return response;
Could you please help me to get the proper solution.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:52 AM
Please share your updated code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:55 AM
Please find the updated code:
UpdateIncData: function(requestData) {
var resp = {};
var IDM = sys_id;
var recordData = request.body.data.requestData.recordData || {};
var upInc = new GlideRecord('incident');
upIn.addQuery('sys_id', IDM);
upIn.query();
if (upIn.next()) {
if (recordData.short_description)
upIn.setValue('short_description', recordData.short_description);
if (recordData.description)
upIn.setValue('description', recordData.description);
if (recordData.assignment_group)
upIn.setValue('assignment_group', recordData.assignment_group);
if (recordData.category)
upIn.setValue('category', recordData.category);
if (recordData.subcategory)
upIn.setValue('subcategory', recordData.subcategory);
upIn.update();
}
resp.message = "Record Updated Successfully";
resp.status = "200";
return resp;
},
type: 'Integration'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 06:01 AM
Please find the updated code:
UpdateIncData: function(requestData) {
var resp = {};
var IDM = sys_id; //From where you are getting value of sys_id? your code is terminating here.
var recordData = request.body.data.requestData.recordData || {};
var upInc = new GlideRecord('incident');
upIn.addQuery('sys_id', IDM);
upIn.query();
if (upIn.next()) {
if (recordData.short_description)
upIn.setValue('short_description', recordData.short_description);
if (recordData.description)
upIn.setValue('description', recordData.description);
if (recordData.assignment_group)
upIn.setValue('assignment_group', recordData.assignment_group);
if (recordData.category)
upIn.setValue('category', recordData.category);
if (recordData.subcategory)
upIn.setValue('subcategory', recordData.subcategory);
upIn.update();
}
resp.message = "Record Updated Successfully";
resp.status = "200";
return resp;
},
type: 'Integration'
};