Create a Scripted Rest API to fetch RITM Variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Requirement is to "Create a Scripted Rest API to fetch RITM Variables"
API should accept RITM number or sys_id as input.
API should fetch all associated catalog variables and values.
response should include : 1. variable name 2. variable label 3. variable value.
To implement this we have used multiple scripts, but when in case of variable type as reference, select box or list collector it is fetching the sys_id instead of display value.
First script :
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var ritmNumber = request.queryParams.ritm_number;
var ritmSysId = request.queryParams.ritm_sys_id;
// Validate input
if (!ritmNumber && !ritmSysId) {
response.setStatus(400);
response.setBody({
error: "Missing required parameter: ritm_number or ritm_sys_id"
});
return;
}
// Retrieve the RITM record
var ritmGR = new GlideRecord('sc_req_item');
if (ritmSysId) {
ritmGR.addQuery('sys_id', ritmSysId);
ritmGR.query();
if (!ritmGR.next()) {
response.setStatus(404);
response.setBody({
error: "RITM not found for sys_id: " + ritmSysId
});
return;
}
} else if (ritmNumber) {
ritmGR.addQuery('number', ritmNumber);
ritmGR.query();
if (!ritmGR.next()) {
response.setStatus(404);
response.setBody({
error: "RITM not found for number: " + ritmNumber
});
return;
}
}
// Fetch ONLY variables
var varList = [];
var grVar = new GlideRecord('sc_item_option_mtom');
grVar.addQuery('request_item', ritmGR.sys_id);
grVar.query();
while (grVar.next()) {
varList.push({
name: grVar.sc_item_option.item_option_new.name.toString(),
label: grVar.sc_item_option.item_option_new.question_text.toString(),
value: grVar.sc_item_option.value.getDisplayValue()
});
}
response.setStatus(200);
if (ritmSysId) {
response.setBody({
ritm_sys_id: ritmGR.getUniqueValue(),
variables: varList
});
} else if (ritmNumber) {
response.setBody({
ritm_number: ritmGR.getValue('number'),
variables: varList
});
}
})(request, response);
-------------------------------------------------------------------------------------------------------
Second script :
-------------------------------------------------------------------
First script is returning sys_id instead of display value completely in case of reference fields or list collector.
Second script is returning display value in some cases, and failing in some cases of reference fields and list collector as well.
Please help identify, what changes are required in the script to fetch display value instead of sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
getting display value is not specific variable or field, this is generic meaning for all catalog items/all variables. so, we cannot provide any specific field name here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Could you please share your expected outcome, along with a few examples to help clarify.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Both service offering and u_group are reference fields but only service offering is picking up
display value if we use the second script, u_group is fetching sys_id.
Like this we need for all the reference/list collector/select box variables, we need to display value . please check the picture added.
