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:26 AM - edited 11-23-2022 05:31 AM
Please check my code I have highlighted few lines where you need to update.
script Include:
UpdateIncData: function(requestData) {
var resp = {};
var recordData = request.body.data.recordData || {}; //please check here, code will be like this requestData.recordData;
var upInc = new GlideRecord('incident');
upIn.addQuery('sys_id', sys_id); //please check "sys_id" field where you have defined this variable, means from where you are getting this value. If not then define 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();
return data;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:29 AM
Hi Roshan,
Could you please paste your code here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:32 AM
Yes I forgot to attach. I have did now please check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:40 AM
I have made the changes what you mentioned above but its not working