Set All fields Read only, once sc task is closed and saved only

Prasanna laksh1
Kilo Contributor

Hi All,

I wrote a UI  policy to make all fields read-only when the Catalog task state is completed. But while changing the state only all fields are getting read-only (refer attached print screens). As per the requirement after saving the form fields should become read-only. Please help me with this.

Thanks in advance!!

1 ACCEPTED SOLUTION

SumanthDosapati
Mega Sage
Mega Sage

Hi @Prasanna lakshmi Thota 

UI policy works onChange as well. 

So in your case, you need to deactivate that ui policy and write an onLoad client script as below

if(g_form.getValue('state') == '3') //check closed complete backend value once
{
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
    g_form.setReadOnly(fields[x], true);
}
}

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

View solution in original post

5 REPLIES 5

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Write simple on load client script because UI policy runs both on change as well as on load

var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
      g_form.setMandatory(fields[x], true);
}

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

SumanthDosapati
Mega Sage
Mega Sage

Hi @Prasanna lakshmi Thota 

UI policy works onChange as well. 

So in your case, you need to deactivate that ui policy and write an onLoad client script as below

if(g_form.getValue('state') == '3') //check closed complete backend value once
{
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
    g_form.setReadOnly(fields[x], true);
}
}

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

error in first line of code

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

It should be like below,

if(g_form.getValue('state') == '3') 
By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hi Sumanth,

Its perfectly working now.

Many Thanks!!