Business rule query to dot walk

servicenow_devo
Tera Expert

Is there anyway to dotwalk variable field of a table in add or add query .

Thankyou
1 ACCEPTED SOLUTION

Satishkumar B
Giga Sage
Giga Sage

Hi @servicenow_devo 

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('related_case.number', 'STARTSWITH', 'IP'); // Related case number starts with "IP"
    grHR.query();

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

 

 

  • addQuery('assigned_to', gs.getUserID()): Filters the HR cases assigned to the current user.
  • addQuery('related_case.number', 'STARTSWITH', 'IP'): Filters HR cases with related cases where the case number starts with "IP".

 

Happy Learning
…………………………………………..
Mark it helpful 👍and Accept Solution !! If this helps you to understand.

 

View solution in original post

3 REPLIES 3

Markus Kraus
Kilo Sage

Can you provide the script that you already have? Is this a for a query business rule?

At the moment i think you need something like this:

var caseGr = new GlideRecord('sn_hr_core_case');
var ootbIsDynamicMeSysID = '90d1921e5f510100a9ad2572f2b477fe';
var qc = caseGr.addQuery('assigned_toDYNAMIC' + ootbIsDynamicMeSysID);
qc.addOrCondition('number', 'STARTSWITH', 'IP');
caseGr.query();
while (caseGr.next()) {
  // do something with caseGr
}

if it should be used to filter the shown cases dynamically for the user, the script looks a little different of course:

var ootbIsDynamicMeSysID = '90d1921e5f510100a9ad2572f2b477fe';
var qc = current.addQuery('assigned_toDYNAMIC' + ootbIsDynamicMeSysID);
qc.addOrCondition('number', 'STARTSWITH', 'IP');

 

Satishkumar B
Giga Sage
Giga Sage

Hi @servicenow_devo 

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('related_case.number', 'STARTSWITH', 'IP'); // Related case number starts with "IP"
    grHR.query();

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

 

 

  • addQuery('assigned_to', gs.getUserID()): Filters the HR cases assigned to the current user.
  • addQuery('related_case.number', 'STARTSWITH', 'IP'): Filters HR cases with related cases where the case number starts with "IP".

 

Happy Learning
…………………………………………..
Mark it helpful 👍and Accept Solution !! If this helps you to understand.

 

Ehab Pilloor
Mega Sage

Hi @servicenow_devo,

Build the query you want on the list of records in the table using filter and run it. Then right click on the breadcrumbs and copy query. Use addEncodedQuery('PASTE_YOUR_QUERY_HERE') method. 

This is the easier method, do try it.

 

If you found my reply useful, please mark it as Solution and Helpful.

 

Thanks and Regards,

Ehab