- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 03:35 AM
Hi ,
I have a UI policy in sc_task for
conditions : state is one of closed complete/incomplete
UI Action: Time worked = mandatory
now once this is filled and saved it should be readonly . But if I up[date the same UI policy it is not allowing me to fill the field .
How can I make this read only once already filled in.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 03:47 AM - edited 04-22-2025 03:49 AM
add extra condition here and ensure UI policy doesn't run on form load
conditions : state is one of closed complete/incomplete AND Time Worked is empty
OR
use onchange client script on State field, UI Type - ALL
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// Check if the state is one of 'Closed Complete' or 'Closed Incomplete'
var state = g_form.getValue('state');
if (state == 'Closed Complete' || state == 'Closed Incomplete') {
g_form.setMandatory('time_worked', true);
// Check if 'Time worked' has a value and make it read-only if it does
var timeWorked = g_form.getValue('time_worked');
if (timeWorked != '') {
g_form.setReadOnly('time_worked', true);
} else {
g_form.setReadOnly('time_worked', false);
}
} else {
g_form.setMandatory('time_worked', false);
g_form.setReadOnly('time_worked', false);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 03:47 AM - edited 04-22-2025 03:49 AM
add extra condition here and ensure UI policy doesn't run on form load
conditions : state is one of closed complete/incomplete AND Time Worked is empty
OR
use onchange client script on State field, UI Type - ALL
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// Check if the state is one of 'Closed Complete' or 'Closed Incomplete'
var state = g_form.getValue('state');
if (state == 'Closed Complete' || state == 'Closed Incomplete') {
g_form.setMandatory('time_worked', true);
// Check if 'Time worked' has a value and make it read-only if it does
var timeWorked = g_form.getValue('time_worked');
if (timeWorked != '') {
g_form.setReadOnly('time_worked', true);
} else {
g_form.setReadOnly('time_worked', false);
}
} else {
g_form.setMandatory('time_worked', false);
g_form.setReadOnly('time_worked', false);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 05:23 AM
Thanks @Ankur Bawiskar that was really silly yep the extra condition worked out perfectly as well as CS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 04:06 AM
are you making the field mandatory via UI policy?
If yes then simply add this condition
conditions : state is one of closed complete/incomplete AND Time Worked is empty
Also create another onLoad client script which checks if state is Closed Complete or Closed Incomplete and if Time worked is filled, then make it readonly
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 05:07 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader