current.UserID ==gs.getUser().isMemberOf(current.assignment_group.toString()) is not working

SNOW32
Giga Expert

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

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

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:

find_real_file.png

 

find_real_file.png

 

 

The only bit of code you need would be in the "Condition" field on the Advanced tab:

!gs.getUser().isMemberOf(current.assignment_group.getDisplayValue())

find_real_file.png

View solution in original post

10 REPLIES 10

Hi Paul,

Yes, Jim's Solution is working.

Thanks for the explanation for "isMemberOf() is available in scope" topic 🙂

Regards,

Swati

Much Thanks Jim 🙂

It was helpful.

I'm glad that worked for you.  The less scripting we do the better.

🙂

Hi Jim,

I need one more help. I need to send a notification with the same case (if user added additional group but user does not belong to assignment group). And I used the same condition in notification script but unfortunately its not working.

Please refer the screenshot and script below:

find_real_file.png 

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

var worknotes = current.comments.getJournalEntry(1);

if (worknotes !='' && sys_updated_by!= gs.getUser().isMemberOf(current.assignment_group.getDisplayValue())) {

template.print("Latest Additional Comments:");

template.print(current.comments.getJournalEntry(1));

}

})(current, template, email, email_action, event);

 

As I am the beginner in coding and scripting. Please provide the solution for the same as well.

 

Thanks,

Swati