Query business rule help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I am trying to run a query business rule to check on multiple conditions which works one way or the other.
If I run the Ismemberof condition or the qc and/or condition within query BR separately it works. But when I try to combine both to check, only the qc condition works and does not include the ismemberof in encoded query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
check this link
Using operator (^NQ) in encoded queries causes incorrect reference links in the list view
try this once
var encodedQueryParts = [];
if (gs.getUser().isMemberOf("ABC")) {
encodedQueryParts.push("parent.u_service_owner=2122342312");
}
if (gs.getUser().isMemberOf("DEF")) {
encodedQueryParts.push("parent.u_service_owner=232323432");
}
var qc = current.addQuery("assigned_to", current.getValue("sys_id")); // comparison with user sys_id
qc.addOrCondition("opened_by", current.getValue("sys_id"));
// Combine 'assigned_to' and 'opened_by' with OR explicitly
if (qc.hasCondition()) {
var fallbackQuery = "assigned_to=" + current.getValue("sys_id") + "^ORopened_by=" + current.getValue("sys_id");
encodedQueryParts.push(fallbackQuery);
}
// Join all parts with OR and apply as encoded query
if (encodedQueryParts.length > 0) {
var combinedEncodedQuery = encodedQueryParts.join("^OR");
gs.addInfoMessage("Combined Query: " + combinedEncodedQuery);
current.addEncodedQuery(combinedEncodedQuery);
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Thanks for the response Ankur. But the script which you have given is same as what I have mentioned in the question. What is the difference?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Sorry I missed that
I believe your script is using that NQ in query business rule which gives inconsistent result
please check the KB link I shared
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I checked the kb article.
But ultimately I get the correct encoded query result in gs.addInfoMessage("Complete query: " + combinedQuery); where I am trying to print.