Client script to make a field mandatory for particular assignment groups
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 05:44 AM
I belatedly realised that using UI Policy to make a field mandatory for particular assignment groups doesn't really work until the form is saved as there is no On Change option. I have been trying to locate knowledge articles that will allow me to borrow a Client Script but without much success.
My particular challenge is that I only want the field to be mandatory for groups that all sit under the same Parent group. Is this possible? I am ok to have the field visible to all, but just need to be Mandatory if the incident state is Resolved and the assignment group is a member of the 'All DW Groups' parent group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 06:15 AM
Thanks.
Ideally, I would only make the field visible to particular assignment groups when the incident was put in a Resolved state and at that point, make it mandatory. It would need to work for both newly logged incidents and ones that are reassigned as a part of the closure process.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 06:36 AM
I tried to recreate this, I guess the dot walk condition is not working as expected.
So Client script is the way. You will need 2 onchange client scripts , one that runs onchange of state (check if state is new or resoled and Assignment group.parent = XXX) and second On change Client script that runs on change of Assignmment group (check if state is new or resoled and Assignment group.parent = XXX)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 06:24 AM
Hi @Kevin Parker ,
If ui policy is not working you can achieve this by onchange client script and Display Business rule as mentioned below ,
Onchange Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == 6) //checking state is resolved
{
if (g_scratchpad.isParent == '8a5055c9c61122780043563ef53438e3') //hardware (parent group name)
{
g_form.setMandatory('description', true);
} else {
g_form.setMandatory('description', false);
}
} else {
g_form.setMandatory('description', false);
}
}
Business rule:
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.isParent = current.assignment_group.parent;
gs.info("line number" + g_scratchpad.isParent);
})(current, previous);
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 09:05 AM
Thanks, I will give that a go and let you know how I get on 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:37 AM
It sort of works! I am still left with the need to Save the record for it to work reliably. It just seems to be that the record has to be saved when changing assignment groups before you change the State to Resolved. If you try to do it all in one go, it doesn't work. When creating a new record from scratch, the script seems to ignore the Parent bit and make the field mandatory for all assignment groups.