- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2022 12:45 PM
Is there any easy way to get the ritm variables along with Ritm fields .please suggest if any body come across .
sysparm_display_value=true&sysparm_fields=number,sys_created_by,variables.one,variables.two
but this needs manualy to add all the variables and fields from it.
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2022 04:56 AM
Hi Rajasekahr,
Create a Scripted REST API.
- Select "System Web Services" > "Scripted Web Servcies" > "Scripted REST APIs" from Application Navigator.
- Select "Query Parameter" and add a mandatory parameter "number" to accept ritm number to get values.
- Select "Resources" tab and create a GET method.
Script
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var queryParams = request.queryParams;
var number = queryParams.number.toString();
var grRitm = new GlideRecord('sc_req_item');
grRitm.addQuery('number', number);
grRitm.query();
if (grRitm.next()) {
// get field values
var fields = grRitm.getFields();
var ritmFields = {};
for (var i = 0; i < fields.size(); i++) {
var glideElement = fields.get(i);
if (glideElement.hasValue()) {
ritmFields[glideElement.getName().toString()] = glideElement.toString();
}
}
// get variables
var grVar = new GlideRecord('sc_item_option_mtom');
grVar.addQuery('request_item', grRitm.sys_id);
grVar.query();
var varList = [];
if (grVar.hasNext()) {
while (grVar.next()) {
var fieldName = grVar.sc_item_option.item_option_new.name.toString();
var type = grVar.sc_item_option.item_option_new.type.toString();
var value = grVar.sc_item_option.value.toString();
varList.push({
'name': fieldName,
'type': type,
'value': value
});
}
ritmFields['variables'] = varList;
}
return ritmFields;
} else {
response.setError(new sn_ws_err.NotFoundError('specified ritm was not found.')); // error - record not found
}
})(request, response);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2023 04:36 AM
Hi rajasekahr,
Have you find the solution for passing multiple ritm's number and fetching the variables.
Thanks,
Sailaja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 03:10 AM
Hello Hitoshi!
That is a great post, thank you for it!
I'm trying to enlarge it a bit. I need to get the display values of the Reference fields.
I tried updating this section below and also adding "&sysparm_display_value=true" (or 'all' instead of 'true') in the url, but no luck so far.
Do you have an idea how can we get the Display values?
Thank you in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 10:27 AM
getFields is not working in scoped application, is there any other way ?
