- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2024 08:28 AM - edited 07-30-2024 08:27 AM
Is there anyway to dotwalk variable field of a table in add or add query .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2024 10:10 AM - edited 07-28-2024 10:16 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2024 10:00 AM
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');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2024 10:10 AM - edited 07-28-2024 10:16 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 03:13 AM
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