How to display group name instead of sys_id

Brandon R1
Tera Contributor

I'm using a Lookup Select Box variable for a 2nd approval in my catalog item. This variable is referencing the sys_user_group table and I have a reference qualifier specifying the 3 groups to be referenced for the drop-down selection in the variable on the form.

find_real_file.png

In order for the workflow to stop (instead of automatically skip) at this "Approval - Group" activity, the lookup value field for the variable has to be the Sys_ID instead of Name. For the Lookup Select Box field on the form, I need it to display the group names NOT the Sys_IDs.

find_real_file.png

I think the best way to achieve this is to use a Catalog Client Script but I'm unsure of how it should be written. Can someone help me with this??

Thanks,
Brandon

 

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Instead of using Lookup Select Box, how about using Reference type? Reference type will enable to  display Name field and still use sys_id.

View solution in original post

11 REPLIES 11

Hitoshi Ozawa
Giga Sage
Giga Sage

If you don't want to use reference type instead of Lookup Select Box, another option is to use Select Box and dynamically fill it with Name with sys_id as the value.

This will require writing a Script Include to query the database table and a Client UI script to dynamically fill the Select Box.

I haven't tested the code but something like below:

Client Script:

function onLoad() {
    var ga = new GlideAjax('usergroup');
    ga.addParam('sysparm_name', 'getUserGroups');

    ga.getXML(fillUserGroup);

    function filluserGroup(response) {
        if (response) {
			g_form.clearOptions('user_group');
            var user_group = response.evalJSON();
            g_form.addOption('user_group', user_group.name, user_group.sys_id);
        }
    }

}

Script Include:

var usergroup = Class.create();
usergroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserGroups: function() {
	var user_group_array = [];
        var svrObj = new GlideRecord('sys_user_group');
        svrObj.addEncodedQuery('<copy refreence qualifier here>');
        svrObj.query();
        if (svrObj.next()) {
			user_group_array.push({"name": svrObj.name, "sys_id": svrObj.sys_id});
        }
	JSON.stringify(user_group_array);
    },
    type: 'usergroup'
});

 

Sudeepta
Tera Contributor

in the lookup label field, add whatever field you want to display.

 

find_real_file.png