Assigned to field validation based on role

abhaysingh98
Tera Contributor

Hello guys,

 

I have a requirement when a CIM task type is survey feedback and assigned to a any resolver group, then only users in that resolver group with the Survey Feedback role(resolver_group_manager) should show in assigned to field not all the users in that group should popup.

To Achieve this requirement I have created one script Include and used it in reference qualifier to filter the assigned to users based on the role but it is not working.

 

Script Include -

var CustomUserRoleFilter = Class.create();
CustomUserRoleFilter.prototype = {
    initialize: function() {},

    getFilteredUsers: function(taskType) {
        if (taskType == '3'){
            return 'sys_idIN' + gs.getRoledUsers('fmg_resolver_group_manager');
        }
    },

    type: 'CustomUserRoleFilter'
};
 
Reference qualifier - 
javascript: new CustomUserRoleFilter().getFilteredUsers(current.getValue('cim_task_type'));
15 REPLIES 15

Brad Bowman
Kilo Patron
Kilo Patron

You can add gs.info or gs.addInfoMessage lines to the SI to confirm the value of taskType and the value of gs.getRoledUsers... (add the log line prior to the return line).  If taskType is null or undefined use

javascript: new CustomUserRoleFilter().getFilteredUsers(current.cim_task_type);

in the override reference qualifier.  In the Script Include, try

return 'sys_idIN' + getRoledUsers('fmg_resolver_group_manager').join(",");

as this should call a Business Rule, not a gs method.  You should also be able to do this within the reference qualifier override

BradBowman_0-1726341614747.png

javascript:if(current.cim_task_type == '3'); return 'sys_idIN' + getRoledUsers('fmg_resolver_group_manager').join(",");

 

 

 

Hi @Brad Bowman  ,

I am getting this error when I removed gs from getRoledUsers.

Error MessagegetRoledUsers undefined, maybe missing global qualifier

And your solution made me confused if I have to use script include or only reference qualifier will ne enough to achieve this requirement.

In your reference qualifier script include function pass 2nd parameter as below

 

 

 

getFilteredusers(current.getValue("task_type") ,current.getValue("assignment_group"));

 

 

 

 

 

then in script include get group like

 

 

 

getFilteredUsers(taskType,task)

 

{

 

If (taskType=="3")

 

    var resGroup = task.assignment_group;

 

    

 

    if (resGroup) 

 

        var userGR = new GlideRecord('sys_user_grmember');

 

        userGR.addQuery('group', resGroup);

 

        userGR.query();

 

        var userList = [];

 

        while (userGR.next()) {

 

            var userId = userGR.user.sys_id;

 

            var userRoleGR = new GlideRecord('sys_user_has_role');

 

            userRoleGR.addQuery('user', userId);

 

            userRoleGR.addQuery('role.name', "resolver_group_manager");

 

            userRoleGR.query();   

 

            if (userRoleGR.next()) {

 

                userList.push(userId.toString());

 

            }

 

        }

 

        

 

      return "sys_idIN"+userList.join(','));

 

 

 

}

I wasn't sure if you can call the out of box Business Rule name getRoledUsers from within your Script Include.  Is the Script Include in the Global scope?  You can try copying the script from this Business Rule and incorporating it into your script, or just use my proposed Reference qualifier as an alternative since calling the Business Rule from a qualifier is how this was designed to work.