- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 02:48 AM
I'm trying to set all fields read only when my state on incident form changes to canceled!!
Here's the code i've written and i'm currently using utah version but this code isn't working. Is there any possibility that getEditablefields() function doesn't work anymore?
If there's any other solution, do let me acknowledge.
That'll will be a great help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 03:14 AM - edited ‎10-16-2023 03:21 AM
Everything you have done is correct except for loop, you didn't set an original value to i.
Please replace: for (var i;i<field.length;i++) with for (var i=0;i<field.length;i++)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue == '8'){
var field = g_form.getEditableFields();
for (var i=0;i<field.length;i++){
g_form.setReadOnly(field[i],true);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 02:53 AM
Hi,
Can you try to create a UI policy and put the code in Scripts -> run script -> execute if true script
UI policy condition -> State is cancelled
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 02:55 AM - edited ‎10-16-2023 02:56 AM
Hi @moni170 ,
You can use table.* ACL to make all fields read only when state is cancelled.
Please refer to below URL as well :
https://www.servicenowelite.com/blog/2019/10/2/access-controls
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 03:12 AM
Hello @moni170 ,
You can create a UI Policy :-
And in the script section you can write the below script:-
function onCondition() {
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
var field = g_form.getValue(fields[x]);
g_form.setReadOnly(fields[x], true);
}
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Alka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 03:14 AM - edited ‎10-16-2023 03:21 AM
Everything you have done is correct except for loop, you didn't set an original value to i.
Please replace: for (var i;i<field.length;i++) with for (var i=0;i<field.length;i++)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue == '8'){
var field = g_form.getEditableFields();
for (var i=0;i<field.length;i++){
g_form.setReadOnly(field[i],true);
}
}
}