Query business rule help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sunday
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
yesterday
so query is correct but for your persona it's not getting applied properly?
can you give your complete business requirement here
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Requirement is to restrict access to table records.
When logged in user is assigned person of ticket, then show those tickets.
When logged in user is opened by person of ticket, then show those tickets.
When logged in user is part of certain group, then show tickets where parent ticket, service owner of ticket is abc for example.
it seems to work when I try to push like below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
since you said it seems to work
then in which case it's not working?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Instead of using addOr condition like below
var qc = current.addQuery("assigned_to", current.getValue("sys_id")); // comparison with user sys_id
qc.addOrCondition("opened_by", current.getValue("sys_id"));
if (qc.hasCondition()) {
var fallbackQuery = "assigned_to=" + current.getValue("sys_id") + "^ORopened_by=" + current.getValue("sys_id");
encodedQueryParts.push(fallbackQuery);
}Tried to have it separately, it seems to work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @imran rasheed ,
Can you please try with below script
var encodedQueries = [];
var userId = gs.getUserID();
if (gs.getUser().isMemberOf("ABC")) {
encodedQueries.push("parent.u_service_owner=2122342312");
}
if (gs.getUser().isMemberOf("DEF")) {
encodedQueries.push("parent.u_service_owner=232323432");
}
// Assignment fallback logic
encodedQueries.push(
"assigned_to=" + userId + "^ORopened_by=" + userId
);
gs.log("encodedQueries = " + encodedQueries);
// Combine with OR
if (encodedQueries.length > 0) {
gs.log("Inside IF = " + encodedQueries.length);
var combinedQuery = encodedQueries.join("^OR");
gs.log("combinedQuery = " + combinedQuery);
gs.addInfoMessage("Complete query: " + combinedQuery);
current.addEncodedQuery(combinedQuery);
}
Also check the values coming in the log.
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak