
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 09:02 AM
Hello,
Thanks in advance to those willing to assist.
- We have added a custom reference field named u_privileged_access_required field to the change request.
- The reference choices are stored in a custom table named u_privileged_access_required.
- The custom table u_privileged_access_required includes a true/false field named u_required_elevated_role.
- When the u_required_elevated_role field is true, we want the u_role field in the change_request table to be visible and mandatory on the Change Request form. If the checkbox is false, we want to hide the u_role field on the change form.
I almost have the script working, but I am encountering an issue with the u_role field staying hidden after the client script runs. When testing, the SHOW/HIDE logic temporarily hides the field based on the client script, but then the u_role reappears on the form. Do I need to tweak the isLoading section?
NOTE: Before trying to write a script, I tried to use a UI Policy. It was weird that I could dot-walk in the condition builder, but the UI policy didn't work either. Based on some other community posts, other folks have experienced difficulties when attempt to solve for similar requirements,
Client Script
Table: change_request
UI Type: All
Type: onChange
Field name: Privileged Access Required
Description: The Role field will be shown for Change Requests with a PAR flagged as requiring an elevated role.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading && newValue === '') {
return;
}
var rec = g_form.getReference('u_privileged_access_required', pullRec);
function pullRec(rec) {
if (rec.u_require_elevated_role == 'true') {
g_form.setDisplay('u_role', true);
g_form.setMandatory('u_role', true);
} else {
g_form.clearValue('u_role');
g_form.setDisplay('u_role', false);
g_form.setMandatory('u_role', false);
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 12:28 PM
Hi @cynlink1 ,
I'm not sure if I've grasped your problem exactly. When I ran your script, I encountered the following issue -
When u_required_elevated_role is false, u_role hides correctly. However, when we clear the value of u_privileged_access_required the u_role is still hidden though it should come back as conditions are not meeting, and to bring back that u_role field you need to refresh the form.
If this is the problem you're encountering, I have a fix! The script below resolves the issue.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.setMandatory('u_role', false);
g_form.setDisplay('u_role', true);
return;
}
var rec = g_form.getReference('u_privileged_access_required', pullRec);
function pullRec(rec) {
if (rec.u_require_elevated_role == 'true') {
g_form.setMandatory('u_role', true);
} else if (rec.u_required_elevated_role == 'false') {
g_form.setDisplay('u_role', false);
g_form.setMandatory('u_role', false);
}
}
}
Here are the scenarios where the script behaves as expected:
- Scenario 1: When u_privileged_access_required is true, the u_role field is displayed as mandatory.
- Scenario 2: When u_privileged_access_required is cleared and you click outside the field, the u_role field becomes non-mandatory.
- Scenario 3: When u_privileged_access_required is false, the u_role field is hidden.
- Scenario 4: When u_privileged_access_required is initially false, clearing it and clicking outside the field now shows the u_role field on the form without requiring a refresh.
So basically if you are making any field mandatory in onchange client script and the script is written after return statement and opposite of this means you are removing mandatory of field above return statement it will work as a reverse if false in client script
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
Thanks,
Astik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 12:28 PM
Hi @cynlink1 ,
I'm not sure if I've grasped your problem exactly. When I ran your script, I encountered the following issue -
When u_required_elevated_role is false, u_role hides correctly. However, when we clear the value of u_privileged_access_required the u_role is still hidden though it should come back as conditions are not meeting, and to bring back that u_role field you need to refresh the form.
If this is the problem you're encountering, I have a fix! The script below resolves the issue.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.setMandatory('u_role', false);
g_form.setDisplay('u_role', true);
return;
}
var rec = g_form.getReference('u_privileged_access_required', pullRec);
function pullRec(rec) {
if (rec.u_require_elevated_role == 'true') {
g_form.setMandatory('u_role', true);
} else if (rec.u_required_elevated_role == 'false') {
g_form.setDisplay('u_role', false);
g_form.setMandatory('u_role', false);
}
}
}
Here are the scenarios where the script behaves as expected:
- Scenario 1: When u_privileged_access_required is true, the u_role field is displayed as mandatory.
- Scenario 2: When u_privileged_access_required is cleared and you click outside the field, the u_role field becomes non-mandatory.
- Scenario 3: When u_privileged_access_required is false, the u_role field is hidden.
- Scenario 4: When u_privileged_access_required is initially false, clearing it and clicking outside the field now shows the u_role field on the form without requiring a refresh.
So basically if you are making any field mandatory in onchange client script and the script is written after return statement and opposite of this means you are removing mandatory of field above return statement it will work as a reverse if false in client script
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
Thanks,
Astik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 06:01 PM
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 06:18 PM
You can actually use a UI Policy to accomplish this. The trick is the dot-walked field MUST be on the form. It can be hidden, but it has to be "on" the form in order for the conditions of the UI Policy to be evaluated properly.