Catalog item variable choices should be visible for perticuler group !

Barathk
Tera Contributor

Hi ,

I have a requirement to create a catalog item with the following variables.
in catalog item  Monitor selection variable have 3 choices,
The choice (34" Monitor) should be visible mentioned group , I need your help for this.
can please help me to achieve this

Current monitor to be replaced: [Open text]

Monitor selection:
- 24" Monitor
- 27" Monitor
- 34" Monitor (Visible to only EPD and Finance only)

4 REPLIES 4

Kieran Anson
Kilo Patron

One solution is to use an onLoad client script that performs a GlideAjax call to check whether the current user (assuming you want this for the current user, and not the requested for) is a member of the mentioned group. If they're not, then the g_form.removeOption function can be used to omit the 34" monitor option.

swathisarang98
Giga Sage
Giga Sage

Hi @Barathk ,

 

Could you please clarify what do you mean by "The choice (34" Monitor) should be visible mentioned group"  do you mean there is a field which store group name or you want to check logged in user or randomly for some group you want to hide this option ?

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

Hi @swathisarang98 
EPD and Finance is group name for this group members only have to select the choice field other group member its should be hide.

@Barathk ,

 

Create a onload Client script and call a script include in the script include check the logged in user is part of epd or finance group and return the binary values, based on these values show or hide the choices,

 

Onload catalog client script:

swathisarang98_0-1715804271180.png

 

 

function onLoad() {
    var ga = new GlideAjax('getMyGroupIn');
    ga.addParam('sysparm_name', 'getGroupDetails');
    ga.getXML(getResponse);
}

function getResponse(response) {
    var ans = response.responseXML.documentElement.getAttribute("answer");
    //alert(ans);
    if (ans == true || ans == 'true') {
        g_form.removeOption('monitor_selection', 34); // change the backend name accordingly
    }
}

 

 

Client callable Script include:

swathisarang98_1-1715804345133.png

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

	getGroupDetails: function(){
		var epd = gs.getUser().isMemberOf('Database');//checking if logged in user is member of database group for testing
		var finance =gs.getUser().isMemberOf('Hardware');//checking if logged in user is member of Finance group for testing
		// gs.info('epd: ' +epd);
		// gs.info('finance: ' +finance);
		if (epd == true || finance == true){
			return false;
		}
		else{
			return true;
		}

	},

    type: 'getMyGroupIn'
});

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang