The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to write a script for variable (request for) editable for only specific group (DELL).

Ambati
Tera Contributor

When Im requesting new task request_for variable need to editable for only DELL support group.

4 REPLIES 4

YaswanthKurre
Giga Guru

Hi @Ambati  ,

 

Write a Onload Script on the catalog/ request form that calls a script include and inside the script include, verify the user is part of the group by using. gs.getUser().isMemberOf("Groupname or sysid here"); and return the value.

 

Thanks,

Yaswanth

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Ambati  

you can use onLoad catalog client script + GlideAjax

-> Catalog client script (Applies on Catalog Task view = True)

-> Script include checks user membership

Script Include: it should be client callable

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

    isUserInDellSupportGroup: function() {
        var dellSupportGroupSysId = 'dell_support_group_sys_id'; // Replace with actual DELL Support group sys_id
        return gs.getUser().isMemberOf(dellSupportGroupSysId);
    },

    type: 'CheckMembership'
});

onLoad catalog client script

function onLoad() {
    var ga = new GlideAjax('CheckMembership');
    ga.addParam('sysparm_name', 'isUserInDellSupportGroup');
    ga.getXMLAnswer(function(response) {
        if (response.toString() === 'true') {
            g_form.setReadOnly('request_for', true);
        } else {
            g_form.setReadOnly('request_for', false);
        }
    });
}

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

@Ambati  

Thank you for marking my response as helpful.

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

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Ambati

You can achieve this using an onLoad Catalog Client Script in combination with a GlideAjax Script Include.

Steps:

  1. Catalog Client Script

    • Applies on: Catalog Task view = True

    • Purpose: Calls the Script Include to check if the user is in the Dell Support group.

  2. Script Include

    • Must be Client Callable.

    • Verifies whether the current user belongs to the Dell Support group.

Script Include

 

 
var CheckMembership = Class.create(); CheckMembership.prototype = Object.extendsObject(AbstractAjaxProcessor, { isUserInDellSupportGroup: function() { var dellSupportGroupSysId = 'dell_support_group_sys_id'; // Replace with actual DELL Support group sys_id return gs.getUser().isMemberOf(dellSupportGroupSysId); }, type: 'CheckMembership' });

 

onLoad Catalog Client Script

 

 
function onLoad() { var ga = new GlideAjax('CheckMembership'); ga.addParam('sysparm_name', 'isUserInDellSupportGroup'); ga.getXMLAnswer(function(response) { if (response.toString() === 'true') { g_form.setReadOnly('request_for', true); } else { g_form.setReadOnly('request_for', false); } }); }





--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/