how to restrict one fields in form section.

prash4
Tera Expert

In Business application ( cmdb_ci_business_app ) form under compliance section there are some fields called "Business Criticality and "IT Tier Classification"

 

in section contacts we have a field called IT application owner which is a mandatory field.

 

 give access to 'Business criticality' field for IT application owner and all other fields should be read only, but when GRCT group logged in, then Business criticality and IT Tier classification both fields should be accessible, and rest fields should be read-only. how can I achieve this, please help.

 

prash4_0-1714396138573.png

 

prash4_2-1714396359260.png

 

 

3 REPLIES 3

Sohail Khilji
Kilo Patron
Kilo Patron

Try onload client script like below :

 

function onLoad() {
    var currentUser = gs.getUser();
    var isITAppOwner = gs.hasRole('it_application_owner');
    var isGRCTGroup = gs.hasRole('grct_group');
    if (isITAppOwner) {
var getFields = g_form.getEditableFields();
for(var i=0;i<getFields.length;i++)
{
g_form.setReadOnly(getFields(i),true);
}      
        g_form.setReadOnly('business_criticality', false);
        
    } else if (isGRCTGroup) {
var getFields2 = g_form.getEditableFields();
for(var i=0;i<getFields2.length;i++)
{
g_form.setReadOnly(getFields2(i),true);
}
        g_form.setReadOnly('business_criticality', false);
        g_form.setReadOnly('it_tier_classification', false);
    } 
}

☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Hi @Sohail Khilji 

Thank you for the quick reply.

Here IT application owner might be anyone, so we can't rely on roles, more over gs is not working in on load,

can you suggest any other way

Thank you

Community Alums
Not applicable

Hi @prash4 ,

I checked your problem I got similar requirement please check below link 

https://www.servicenow.com/community/developer-forum/how-to-check-logged-in-user-is-a-part-of-group-...

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak