- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 08:46 AM
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:
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 01:15 AM
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); } }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 08:49 AM
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 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 01:15 AM
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); } }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 04:08 AM
Did my response help, if yes, feel free to mark my response as correct
Aman Kumar