how to make planned start date and end date fileds readonly when user has change_manager role when change is moved to authorize state?

HARI KISHAN GVS
Mega Sage

Hi Team, 

My requirement is 

make planned start date and end date fileds readonly when user has change_manager role after change is moved to authorize state?

i tried to create a ui policy with conditions as state is authorize and in run scripts 

execute if true 

function onCondition() {
var isManager = g_user.hasRole('change_manager');
if(isManager){
g_form.setReadOnly('start_date', false);
g_form.setReadOnly('end_date', false);
}
}

execute if false

function onCondition() {
g_form.setReadOnly('start_date', true);
g_form.setReadOnly('end_date', true);
}

But, it is NOT working. in New and asses states also start date and end date fields are becoming readonly.

can anyone Please correct my script or provide any other method to solve this.

here are the screen shots of my Ui policy:

find_real_file.png

 

 

find_real_file.png

1 ACCEPTED SOLUTION

HARI KISHAN GVS
Mega Sage

function onLoad() { //Type appropriate comment here, and begin script below var isManager = g_user.hasRole('change_manager'); var st = g_form.getValue('state'); // get the state value here // stateIN-3,-2,-1,0 if (st == '-3' || st == '-2' || st == '-1' || st == '0') { // check if change is in one of Authorise, Scheduled, Implement, Review States if (isManager) { // check if user has sn_change_cab.cab_manager role g_form.setMandatory('start_date', true); g_form.setMandatory('end_date', true); g_form.setReadOnly('start_date', false); g_form.setReadOnly('end_date', false); } else g_form.setMandatory('start_date', false); g_form.setMandatory('end_date', false); g_form.setReadOnly('start_date', true); g_form.setReadOnly('end_date', true); } if (st == '-4' || st == '3') { // for Asses, Closed states g_form.setMandatory('start_date', true); g_form.setMandatory('end_date', true); } }

View solution in original post

3 REPLIES 3

Aman Kumar S
Kilo Patron

Can you check if fields are mandatory in these states, if yes in order to make them read only, you also need to make them non-mandatory.

This line will go just before read only statement

g_form.setMandatory("field_name",false);

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

HARI KISHAN GVS
Mega Sage

function onLoad() { //Type appropriate comment here, and begin script below var isManager = g_user.hasRole('change_manager'); var st = g_form.getValue('state'); // get the state value here // stateIN-3,-2,-1,0 if (st == '-3' || st == '-2' || st == '-1' || st == '0') { // check if change is in one of Authorise, Scheduled, Implement, Review States if (isManager) { // check if user has sn_change_cab.cab_manager role g_form.setMandatory('start_date', true); g_form.setMandatory('end_date', true); g_form.setReadOnly('start_date', false); g_form.setReadOnly('end_date', false); } else g_form.setMandatory('start_date', false); g_form.setMandatory('end_date', false); g_form.setReadOnly('start_date', true); g_form.setReadOnly('end_date', true); } if (st == '-4' || st == '3') { // for Asses, Closed states g_form.setMandatory('start_date', true); g_form.setMandatory('end_date', true); } }

Did my response help, if yes, feel free to mark my response as correct

Best Regards
Aman Kumar