- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2019 11:31 AM
Hello Experts,
I hope you all are doing great. 🙂
I wrote a BR to check the condition if customer added "additional comments" then "State" change into "In Progress" and that customer does not belong to the "Assignment Group".
I got some scripts from community and tried but its not working.
My Business rule is given below:
When: after (Insert, Update)
answer = (isMemberOfForScopedApp(current.assignment_group)); // Note: standard 'isMemberOf' does not work within Scoped App
function isMemberOfForScopedApp(groupID){
var result = false;
if (groupID != ''){
var userID = gs.getUserID();
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", groupID);
gr.addQuery("user", userID);
gr.query();
if (gr.next()){
result = true;
}
}
return result;
}
if (answer == gs.getUserID() || answer == gs.getUser().getDisplayName())
{
current.state = 2;
current.u_feedbacks_state= 2;
current.update();
}
Any ideas on how this might be able to function?
Thanks in advance!
Swati
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2019 01:21 PM
Where did you see that "isMemberOf" does not work in a scoped app? I can't recall using it, but the docs says it should work.
I would change the BR to run Before Insert/Update, and set the following options (including checking the "Advanced" box:
The only bit of code you need would be in the "Condition" field on the Advanced tab:
!gs.getUser().isMemberOf(current.assignment_group.getDisplayValue())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2019 11:55 AM
The above code can't work because the line
answer = (isMemberOfForScopedApp(current.assignment_group));
assign Boolean value to answer variable (true if the current user is member of current.assignment_group). On the other side you use later
if (answer == gs.getUserID() || answer == gs.getUser().getDisplayName())
compares the Boolean answer with user id and user name. Such code can't work. I think it's clear how to fix it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2019 12:32 PM
Hi Oleg,
I tried it with
answer == true but the code didnt work.
Do you have any other solution?
Thanks,
Swati
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2019 01:21 PM
Where did you see that "isMemberOf" does not work in a scoped app? I can't recall using it, but the docs says it should work.
I would change the BR to run Before Insert/Update, and set the following options (including checking the "Advanced" box:
The only bit of code you need would be in the "Condition" field on the Advanced tab:
!gs.getUser().isMemberOf(current.assignment_group.getDisplayValue())

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2019 06:09 PM
Swati I think you may be confusing this with getMyGroups(), which is not available in scoped applications.
isMemberOf() is available in scope.
Verified using Xplore in Madrid:
Global isMemberOf()
Scoped isMemberOf()
The only differences are that in scope isMemberOf() returns a boolean, but in global it returns a string.
I believe Jim's solution is correct.
Once you have followed his instructions, you just need to place this bit in the executeRule function:
current.state = 2;
current.u_feedbacks_state= 2;
current.update();
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022