setting refrence feild list

prem kumar2
Tera Contributor

Hi team,

In interaction form on a Service Operation Workspace when assigned to changes then assignment group feild should show only the groups where assigned to user belongs to we tried to acheive through script include and onchange client script but it is not effected on form.Please Suggest if any other way we can acheive this.Thanks in advance

script include:

client script:Onchange of assined to

var InteractionUtils = Class.create();
InteractionUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getUserGroups: function() {
        var groups = [];
        var groupjoin;
        var userId = this.getParameter('sysparm_userId');
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', userId);
        gr.query();
        while (gr.next()) {
            groups.push(gr.group.sys_id.toString());

        }
        groupjoin=groups.join(",");
        gs.log("alpha" + groups);
        return groupjoin;
    },
    type: 'InteractionUtils'
});



function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var ga = new GlideAjax('InteractionUtils');
   ga.addParam('sysparm_name', 'getUserGroups');
   ga.addParam('sysparm_userId', newValue);
   ga.getXML(getgroups);
  function getgroups(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    alert(answer);
    var filterString = "sys_idIN"+answer.toString();
   
 
    var myListCollector1 = g_list.get("assignement_group");
    myListCollector1.reset();
    myListCollector1.setQuery(filterString);
}
 
 
   
}
1 ACCEPTED SOLUTION

@prem kumar2 

try this

getUserGroups1: function(user) {
        var groups = [];
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', user);
        gr.query();
        while (gr.next()) {
            groups.push(gr.group.sys_id.toString());
        }
        gs.log('sys_idIN'+groups.toString());
        return 'sys_idIN'+groups.toString();
    },

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@prem kumar2 

why not use advanced ref qualifier?

I think you are trying to set the filter for list collector using g_list and this probably is not supported in workspace

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

we have tried using reference qualifier it is still not resolved.

@prem kumar2 

share the scripts created and what debugging have you done so far?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

HI @Ankur Bawiskar 
we have used thi script include:

getUserGroups1: function(user) {
        var groups = [];
        //var userId = this.getParameter('sysparm_userId');
        if (!user) {
            return JSON.stringify([]);
        }

        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', user);
        gr.query();
        while (gr.next()) {
            groups.push(gr.group.sys_id.toString());
        }
        gs.log('sys_idIN'+groups.toString());
        return 'sys_idIN'+groups.toString();
    },
and on the dictionary level we used :
premkumar2_0-1734094723832.png