How to make a catalog item show different variables based on a group or role you are part of.

arohm
Tera Expert

Hey Everyone,


I have a need to change what a user sees on a catalog item based on a role or group membership. I am not too familiar with scripting in SN or business rules. 

The use case is, We have a catalog item for laptop theft. We need this to be "available" for anyone to submit so our Helpdesk team can submit the request as the user so the workflow can auto populate the users CI info for their laptop. We do not want users themselves submitting this request however as they need to speak with the helpdesk to change their password. So we want some sort of script or BR that if a user clicks this catalog item, it shows them a message just stating they need to call User support. But if a user with ITIL role clicks it, they see all the variables. 

What would be the easiest way to accomplish this?

7 REPLIES 7

Hi @arohm ,

I think 2nd code will not work

Please use "g_form.setMandatory('variable', false);"

If you think there are many fields may be try this .(not sure if it will work on catalog item.but give it a try)

//set mandatory false
for (var i = 0; i < g_form.elements.length; i++)
{
    var el = g_form.elements[i];
    var fieldName = el.fieldName;
    g_form.setMandatory(fieldName, false);
}

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

Thanks for the heads up. I couldn't get this to work so i went a different route. Its still a client script. I just have a alert message pop up when you dont have the ITIL role and then it auto redirects you to the home page. 

I still would like to figure out this whole hiding variables and marking fields as not mandatory though. 

Community Alums
Not applicable

Hi @arohm ,

You can use this onLoad Client script

function onLoad() {
var userRoles = g_user.hasRoles();
if (!userRoles.includes('itil')) {
alert('You are not authorized to submit this request. Please contact User Support.');
g_form.setReadOnly(true); // Optionally, make the form read-only, if you need
}
}

Please mark as Accepted Solution if this solves your query .