- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2021 02:35 AM
Good Morning, We are trying to find a Rest API that will link the "sc_task" or the "sc_req_item" tables to the variables and the answers to these so we can create a report in PowerBI. I believe the table is "sc_item_option_mtom" but I am unable to find a way to link this to the correct table to link all things together. We need to pull out 1 particular field in the variables list and link to the request so we have all details.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2021 12:38 AM
Morning,
This didnt work as expected and I kept getting a failure but I found this website "https://snprotips.com/blog/2016/7/15/scripted-rest-apis-in-servicenow-how-to-retrieve-catalog-item-variables" from a few years ago and following this process end to end working. Thanks for your help and pointing me in the right direction
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2021 02:39 AM
Ok, your requirement is to have an API, and when you will call with RITM or TASK number that will return all the variables values of the respective task or RITM.please correct me if I am wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2021 02:48 AM
Good Morning Pradyumna,
That is correct, as per my screen shot, I would like to query the task / request and get all variables assigned to this and their values.
Thanks
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2021 03:10 AM
Please create a Scripted Rest API for this and edit the script as per your field requirement.
step1:
Create a scripted Rest API:
step 2 create one resource record under this scripted rest server.
Then add the below script and modify it as per your requirement:
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var result = {};
var number = request.body.data.number.toString();
if (number != '') {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('number', number);
ritm.query();
if (ritm.next()) {
variable = {};
//variable.request_for = ritm.variables.requested_for.getDisplayValue();
//variable.costcenter = ritm.variables.costcenter.getDisplayValue();
variable.requested_for=ritm.request.getDisplayValue();
result.variables = variable;
result.status = 'success';
} else {
result.status = 'fail';
result.reason = 'Given number not avaibale in the table.';
}
} else {
result.status = 'fail';
result.reason = 'number is empty.';
}
return result;
})(request, response);
output as per my script:
Please mark it correct and helpful if my efforts really help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2021 12:38 AM
Morning,
This didnt work as expected and I kept getting a failure but I found this website "https://snprotips.com/blog/2016/7/15/scripted-rest-apis-in-servicenow-how-to-retrieve-catalog-item-variables" from a few years ago and following this process end to end working. Thanks for your help and pointing me in the right direction