If User is having Agent and Manager Role then he needs to edit the fields

Priya madyapgol
Tera Contributor

Hi Everyone,

I have one requirement on Case table.

 

I have one user and who is agent role as well and manager role as well,

and we have one condition that is, Agent can edit all the fields from case form, but manager can't edit those fields,

but here in my condition the user is both agent as well as manager, so he should edit all the fields, 

I have written one UI Policy for restriction of editing fields for Manager.


function onCondition() {

    if(g_user.hasRole('sn_customerservice_manager'))

    {

        g_form.setReadOnly('u_case_sub_category',true);

        g_form.setReadOnly('account', true);

        g_form.setReadOnly('u_tower',true);

        g_form.setReadOnly('u_case_category',true);

    }

    else{

        g_form.setReadOnly('u_case_sub_category',false);

        g_form.setReadOnly('account', false);

        g_form.setMandatory('account', true);

    }

}


What changes i need to do in the above code, when the user is agent and manager both at that he can able to edit the fields.

 

 

Thanks,
Priya.




1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Priya madyapgol 

you should use onLoad client script rather than using script in UI policy

something like this

function onLoad() {
    // Check if the user has both agent and manager roles
    var isAgent = g_user.hasRole('sn_customerservice_agent');
    var isManager = g_user.hasRole('sn_customerservice_manager');

    if (isManager && !isAgent) {
        // If the user is only a manager, make fields read-only
        g_form.setReadOnly('u_case_sub_category', true);
        g_form.setReadOnly('account', true);
        g_form.setReadOnly('u_tower', true);
        g_form.setReadOnly('u_case_category', true);
    } else {
        // If the user is an agent (or both agent and manager), make fields editable
        g_form.setReadOnly('u_case_sub_category', false);
        g_form.setReadOnly('account', false);
        g_form.setReadOnly('u_tower', false);
        g_form.setReadOnly('u_case_category', false);
        g_form.setMandatory('account', true);
    }
}

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Priya madyapgol 

Would you mind closing your earlier questions by marking appropriate response as correct?

Members have invested their time and efforts in helping you.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@Priya madyapgol 

you should use onLoad client script rather than using script in UI policy

something like this

function onLoad() {
    // Check if the user has both agent and manager roles
    var isAgent = g_user.hasRole('sn_customerservice_agent');
    var isManager = g_user.hasRole('sn_customerservice_manager');

    if (isManager && !isAgent) {
        // If the user is only a manager, make fields read-only
        g_form.setReadOnly('u_case_sub_category', true);
        g_form.setReadOnly('account', true);
        g_form.setReadOnly('u_tower', true);
        g_form.setReadOnly('u_case_category', true);
    } else {
        // If the user is an agent (or both agent and manager), make fields editable
        g_form.setReadOnly('u_case_sub_category', false);
        g_form.setReadOnly('account', false);
        g_form.setReadOnly('u_tower', false);
        g_form.setReadOnly('u_case_category', false);
        g_form.setMandatory('account', true);
    }
}

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

@Priya madyapgol 

Hope you are doing good.

Did my reply answer your question?

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

@Priya madyapgol 

Hope you are doing good.

Did my reply answer your question?

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