Business Rule in sc_req_item cannot get data from sc_request

Rafael Pinto
Tera Contributor

Hello. I created a business rule (after insert, global scope) in the sc_req_item table. This rule needs to get a GlideRecord in the sc_request table of the REQ record associated with the RITM being created.

 

var req = new GlideRecord("sc_request");
req.get(current.getValue("request"));

 

After that, data from the REQ is prepared in order to be sent to a REST integration.

However, the business rule is not able to get this GlideRecord. I use gs.info to verify if the req variable is getting the necessary record, but it returns null.

Does anyone know why this happen and if there is a way to fetch this REQ GlideRecord in the RITM Business Rule?

Thank you.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Rafael,

I was seeing the same in my PDI after Insert.  For some reason, changing it to the longer syntax seems to work:

function executeRule(current, previous /*null when async*/) {
	var req = new GlideRecord("sc_request");
	req.addQuery('request', current.request);
	req.query();
	if (req.next()) {
		gs.addInfoMessage('number = ' + req.number)
	}
})(current, previous);

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Hi Rafael,

I was seeing the same in my PDI after Insert.  For some reason, changing it to the longer syntax seems to work:

function executeRule(current, previous /*null when async*/) {
	var req = new GlideRecord("sc_request");
	req.addQuery('request', current.request);
	req.query();
	if (req.next()) {
		gs.addInfoMessage('number = ' + req.number)
	}
})(current, previous);

Luxo Nadappan
Tera Guru

Hi , 

 

Seems there is already solution   available here Servicenow importance of getValue and getDisplayValue method | ServiceNow getters | Servicenow Learn...

Also there is request field available in "RITM" table  and you can access the same via current. Request.

 

Regards,

Luxo