Is it possible to use dot walking in a Query Business Rule?

abrahams
Kilo Sage

I am struggling to get dot walking in a query business rule.

 

For a given role, I'm trying to show only HR tasks when the parent.hr_service cases is a desired Service.

 

This is a little example of the syntax I tried but it doesn't appear to work in a query business rule.  <sys_id> in my query is actually the sys_id of the HR Service.

 

var qry = current.addQuery('parent.hr_service', '<sys_id>');
 
Does anyone have any ideas how I could get this to work?
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Dot-walking doesn't seem to work, at least in this case.  Here's a workaround for the Query Business Rule script:

function executeRule(current, previous /*null when async*/) {
	var resultsArr = [];
	var parGr = new GlideRecord('sn_hr_core_task');
	parGr.query();
	while (parGr.next()) {
		if (parGr.parent.hr_service == '9e28cde49f331200d9011977677fcf00') {
			resultsArr.push(parGr.sys_id.toString());
		}
	}
	current.addQuery('sys_id', 'IN', resultsArr.join(','));  
})(current, previous);

 

View solution in original post

5 REPLIES 5

Sid_Takali
Kilo Patron
Kilo Patron

Hi @abrahams Try below code and modify accordingly

var hrServiceSysId = current.sys_id; 
var gr = new GlideRecord('hr_task'); 
gr.addQuery('parent.hr_service', hrServiceSysId);
gr.query();

Brad Bowman
Kilo Patron
Kilo Patron

Dot-walking doesn't seem to work, at least in this case.  Here's a workaround for the Query Business Rule script:

function executeRule(current, previous /*null when async*/) {
	var resultsArr = [];
	var parGr = new GlideRecord('sn_hr_core_task');
	parGr.query();
	while (parGr.next()) {
		if (parGr.parent.hr_service == '9e28cde49f331200d9011977677fcf00') {
			resultsArr.push(parGr.sys_id.toString());
		}
	}
	current.addQuery('sys_id', 'IN', resultsArr.join(','));  
})(current, previous);

 

For some reason, I didn't think we should use GlideRecord in a query business rule but this does work.  Thank you!

Sumanth16
Kilo Patron

Hi @abrahams ,

 

In a Business Rule, you can use dot-walking to query related tables.

 

 

(function executeRule(current, previous /*null when async*/) {
    // Instantiate a GlideRecord object for the HR table
    var grHR = new GlideRecord('hr_case');
    
    // Query the HR table with dot-walked conditions
    grHR.addQuery('assigned_to', gs.getUserID()); // Assigned to me
    grHR.addOrCondition(grHR.parent.hr_service=='xxxx'); // hr service sysid
    grHR.query();

    while (grHR.next()) {
        // Process each record
        gs.info('Found HR Case with number: ' + grHR.number);
    }
})(current, previous);