- 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
05-31-2022 06:23 PM
Don't mention this in URL and that will return you all the fields available in the RITM. If you want to get only specific fields then you can create a scripted REST API and you can show only fields that you want to send in response.
Please mark correct and helpful if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2022 06:44 PM
as per my understanding if they give our url they will access our ritm record variables.
scripted rest api do you have sample codes how to get the ritm variables, i had tried some things in community it was not working properly.
- 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
06-06-2022 02:37 AM
Thanks for your response it is working for single RITM
Please suggest it is possible to pass multiple ritm's number or any filter based on filter we can able to fecth multiple RITM numbers?
