In Change Table, Field should be mandatory and visible only to Change Manager in New State.

SajithM
Tera Contributor

In Change Table, Field should be mandatory and visible only to Change Manager in New State.

6 REPLIES 6

Community Alums
Not applicable

Hi @SajithM ,

You can use a UI policy to set the fields mandatory and visible , then  use the run scripts option like below:

 

 

function onCondition() {

if(!g_user.hasRoleExactly('change_manager')) {
	g_form.setReadOnly('<name_of_field>', true);
}

}

 

 

No Luck, Not sure what's the issue though.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @SajithM 

You didn’t specify which field should be mandatory and why, specifically for the Change Manager. You can follow the UI policy as suggested by @Sandeep Dutta . Also, since it is mandatory only for the Change Manager, make sure that the field is visible in the new state.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@SajithM 

you can use onLoad client script for this

function onLoad() {
    var isChangeManager = g_user.hasRoleExactly('change_manager');
    var currentState = g_form.getValue('state');
    var fieldName = 'your_field_name'; // Replace with your actual field name

    if (currentState.toString() == '-5') { // Assuming 'New' state value is '-5'
        g_form.setVisible(fieldName, isChangeManager);
        g_form.setMandatory(fieldName, isChangeManager);
    } else {
        g_form.setVisible(fieldName, true);
        g_form.setMandatory(fieldName, 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