The CreatorCon Call for Content is officially open! Get started here.

Limit assignment group selection based on user's group + one exception

JohnDF
Mega Sage

Hi everyone,

 

I need help with a advanced reference qualifier. 

If logged in user belong to a group which name start with "SN-CC" then he should see only his groups he belongs to + the one exception group with sys_id xyz.

 

All other logged in user which not belongs to a group which name start with "SN-CC" then he should see all assingment groups.

Thanks for help!

1 ACCEPTED SOLUTION

Hello @JohnDF ,

 

Does this resolved your issue?? If yes, Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.

 

Regards,

Siddhesh

View solution in original post

16 REPLIES 16

Hi @JohnDF, You can put the log statements inside the script include function like below.

 

var GroupFilter = Class.create();
GroupFilter.prototype = {
    initialize: function() {},
    filterGroups: function() {
gs.log("John - Inside Script Include");
        var user = gs.getUserID();
        var groupIds = [];
        var groupFilter = '';
        var gr = new GlideRecord('sys_user_grmember');
        gr.addEncodedQuery('user=' + user + '^group.nameSTARTSWITHSN-CC');
        gr.query();
        while (gr.next()) {
            groupIds.push(gr.group.sys_id);
        }
gs.log("John - GroupIds - " +groupIds);
        if (groupIds.length > 0) {
            groupFilter = 'sys_idIN' + groupIds.join(',') + ',c6c828c453751300ba3dddeeff7b1219'// xyz is the sys_id of the exception group
gs.log("John - groupFilter - " +groupFilter);
            return groupFilter;
        }
    },
    type: 'GroupFilter'
};
 
Open the script logs in your instance and search message starts with John and you should be able to see the logs.
 
Regards,
Sunil
 

Namrata Ghorpad
Mega Sage

Hello @JohnDF ,

Write before query business rule on "sys_user_group" table and write the code like below.

(function executeRule(current, previous /*null when async*/ ) {
var bl = false;
    var loggedInUser = gs.getUserID();
    var group = new GlideRecord('sys_user_grmember');
    group.addQuery('user', loggedInUser);
    group.addEncodedQuery("group.nameSTARTSWITHSN-CC");
    group.query();
    if (group.next()) {
        bl = true;
    }
    if (bl == true) 
  {		
current.addEncodedQuery("sys_idINjavascript:gs.getUser().getMyGroups();^ORsys_id=group_sys_id");
        }
})(current, previous);		

 

Please mark my answer as correct and helpful if it helps to resolve your issue.

Regards,

Namrata