How to get RITM variables display value using REST API?

Rajesh Mushke
Mega Sage
Mega Sage

Hi All,

How to get RITM variables display value using REST API with out using scripted REST API.

Can someone help on this.

Thanks,

Rajashekhar Mushke



Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
23 REPLIES 23

Priyanka Chandr
Mega Guru

Hi,

Below blog will help you to achieve this

https://snprotips.com/blog/2016/7/15/scripted-rest-apis-in-servicenow-how-to-retrieve-catalog-item-v...

Please mark my answer correct and helpful.

Thanks,

Harsh Vardhan
Giga Patron

create one script include and there you will use getDisplayValue() while fetching the variable value. 

now in your scripted rest api use that script include. 

 

sample code for getting all ritm variables. make the changes based on your need. 

 

	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('request', current.sys_id);
	gr.query();
	while (gr.next()) {
				

			var set = new GlideappVariablePoolQuestionSet();
			set.setRequestID(gr.sys_id);
			set.load();
			var vs = set.getFlatQuestions();
			for (var i = 0; i < vs.size(); i++) {
				if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
					
					gs.print("\n"+ '<b>' +vs.get(i).getLabel() + " = " + '</b>' + vs.get(i).getDisplayValue() + "\n");

				}
}
			

 

blog for further details to use script include inside the scripted rest api. 

 

https://www.servicenowtechminds.com/single-blog.php?id=23

 

If my answer helped you, kindly mark it as correct and helpful

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Rajashekhar,

Do you require scripted REST API?

Because this is possible using OOB table API as well.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur, No, we don't want to use the scripted REST API, could you please suggest me how to achieve with using oob table? Thanks, Rajashekhar Mushke


Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke