when state is close complete then it should make the field readonly after saving the form on sc_task

snow34
Tera Contributor

when state is close complete then it should make the field readonly after saving the form on sc_task

1 ACCEPTED SOLUTION

Use Below onLoad Client Script:-    It will work after saving the record



function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('state') == '3') {
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
// by default the mandatory fields can not be set as readonly
// Make the field non-mandatory before making it readonly
g_form.setMandatory(fields[x], false);
g_form.setReadOnly(fields[x], true);
}
}
}

 

 

Please mark my answer as helpful/correct if it resolves your query.

 

Regards,

Gunjan Kiratkar

Consultant - ServiceNow, Cloudaction

Rising Star 2022

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

11 REPLIES 11

Use Below onLoad Client Script:-    It will work after saving the record



function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('state') == '3') {
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
// by default the mandatory fields can not be set as readonly
// Make the field non-mandatory before making it readonly
g_form.setMandatory(fields[x], false);
g_form.setReadOnly(fields[x], true);
}
}
}

 

 

Please mark my answer as helpful/correct if it resolves your query.

 

Regards,

Gunjan Kiratkar

Consultant - ServiceNow, Cloudaction

Rising Star 2022

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

I tried but this also didn't worked 

Share the screenshot of where you have written down this script.

I have tested in my PDI it is working. Make sure to write this script in a global scope application.

 

Regards,

Gunjan


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Michael de Boer
Giga Guru

Check the UI Policy "Make fields read-only on close" on the incident table.
That does the same thing you want, but for incidents.

Regards,

Michael

Regards,
Michael

Please mark the suggestion as helpful/like, if you find it useful to you or others who wants to refer similar content.
Please mark the solution as correct, if the answer provided has resolved your query.

Voona Rohila
Kilo Patron
Kilo Patron

Hi,

If you need it after save and state value changes then

Write Onload client script and get the state value,based on state value make the field read-only.

sample: //modify accordinglly

if(g_form.getValue('state') == 'closed_complete')

{

//make fields read-only

}

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP