how to retrieve the RITM variables using the Rest API's

rajasekahr
Tera Guru

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.

 

 

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Rajasekahr,

Create a Scripted REST API.

  1. Select "System Web Services" > "Scripted Web Servcies" > "Scripted REST APIs" from Application Navigator. 
    find_real_file.png
  2. Select "Query Parameter" and add a mandatory parameter "number" to accept ritm number to get values.
    find_real_file.png
  3. Select "Resources" tab and create a GET method.
    find_real_file.png

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);

View solution in original post

7 REPLIES 7

Hi rajasekahr,

Have you find the solution for passing multiple ritm's number and fetching the variables.

 

Thanks,

Sailaja

 

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.

 

LachezarKanav1_0-1681121345443.png

Do you have an idea how can we get the Display values?

Thank you in advance!

getFields is not working in scoped application, is there any other way ?