- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2023 07:49 PM
I am making entire form read only on a condition with a on load client script with code as below :
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
This is because i have lot of conditional hide and display on form.
Now the requirement is to make one single field editable on that condition.
Can i achieve this using same client script or creating something new but keeping this Client Script.
When i am adding a line to make the field mandatory in same Client Script. The Client Script is not working at all.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2023 08:30 PM
make the field which you want to be editable once you end the for loop
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
g_form.setReadOnly('fieldName', false);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2023 08:06 PM
Hello @aditiojha ,
Try making all the fields read only and then add an if condition make that single field editable and then mandatory.
Script:
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
if(condition){
g_form.setReadOnly("field_name", false);
g_form.setMandatory("field_name", true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2023 08:26 PM
Hi @aditiojha ,
The Best approach is to use UI Policy here to make fields read only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2023 08:38 PM
Thanks Sandeep. There were lot of fields and lots of conditional hide and display hence using UI policy was not possible. However another solution to this post helped me using the same client script. Appreciate your time and response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2023 08:30 PM
make the field which you want to be editable once you end the for loop
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
g_form.setReadOnly('fieldName', false);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader