How to make one variable readonly after task is closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 10:43 PM - edited 11-13-2024 10:45 PM
Hi Team,
for making sc_task variables readonly, I have written a UI Policy applies on catalog task and below is my script.
Now I have another variable on task form which is mandatory, after saving the record variable is automatically changing to readonly. however I want that variable readonly when state is closed complete, I have used below code, but it is not working. means when catalog task state is in open or work in progresss, at that time also variable is readonly, I want that to be editable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 10:52 PM
Hi @Gopal14 ,
try below code.
function onLoad() {
//Type appropriate comment here, and begin script below
var shortDescription = g_form.getValue('short_description');
var state = g_form.getValue('state');
if (shortDescription == 'Confirm Receipt of Old Machine' || state == 3) {
g_form.setMandatory('confirm_which_stockroom_this_has_been_returned_to', false);
g_form.setReadOnly('confirm_which_stockroom_this_has_been_returned_to', true);
}
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 11:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 03:00 AM
Hi @Gopal14 ,
Is this worked? if yes then reason is you can not make field read only if field have empty value with mandatory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 03:26 AM
Hi @Gopal14 ,
It seems the field is becoming read-only due to the if condition:
if (shortDescription == 'Confirm Receipt of Old Machine' || state == 3) instead use if (shortDescription == 'Confirm Receipt of Old Machine' && state == 3)
OR , simply
if (state == 3)
If you are using the if condition with ll operator the onload script execute even if short description condtion matches.