- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 12:05 PM
Im trying to make all the fields on the incident form as read only if the condition is met, but the OOB fields stay editable:
function onLoad() {
//Type appropriate comment here, and begin script below
var us = g_user.userID;
if (us != g_form.getValue('assigned_to')) {
for (var x = 0; x < g_form.elements.length; x++) {
g_form.setMandatory(g_form.elements[x].fieldName, false);
g_form.setReadOnly(g_form.elements[x].fieldName, true);
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 01:13 PM
I'm assuming this is related to this question: Write ACL on the task table
You should continue with the Access Control method because this Client Script would NOT protect your records in a List view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 01:06 PM
Hi, assuming that you have checked and confirmed that your script is triggered, your syntax is correct and that your script is setting some fields on the form read only? Then based on your form screen shot still showing mandatory and editable fields I would guess that there are client scripts or Ui policies running after your onLoad client script.
I don't think this is sourced from official SNC documentation but it provides a nice graphical view of execution order.
Script Execution in ServiceNow: An In-Depth Look | LinkedIn
Also curious regarding your business drivers\requirements?
What will happen when there is no assignee and\or the task is new?
How are tasks managed if the assignee is absent?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 01:13 PM
I'm assuming this is related to this question: Write ACL on the task table
You should continue with the Access Control method because this Client Script would NOT protect your records in a List view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 01:50 PM
BUT, to answer the question, yes, UI Policies are overriding the Client Scripts because they run after the onLoad Client Scripts.