How to make Incident Worknote OR Comment mandatory on Priority update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 12:26 PM
I have seen many articles related to making a Worknote mandatory when Incident Priority is updated, however my requirement is a little bit different:
I want EITHER a Worknote or Comment to fulfill the mandatory requirement.
We already have the Client Script seen in the SNOW Community for making only a Worknote mandatory:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || g_form.isNewRecord())
return;
else if (newValue == oldValue)
g_form.setMandatory("work_notes", false);
else
g_form.setMandatory("work_notes", true);
}
And this was my stab at it, but it's not working.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || g_form.isNewRecord())
return;
if (newValue != oldValue)
g_form.setMandatory("comments", true) || g_form.setMandatory("work_notes", true);
//else if (newValue == oldValue)
g_form.setMandatory("work_notes", false) || g_form.setMandatory("comments", false);
}
Is there a better way to achieve this, or do I just need a small adjustment to the code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 12:36 PM
hello
You need to have a condition in IF for that like and followed by else because if there is no else part the script wont understand what it should me make mandatory.Either it should be like below code or both mandatory.
Either ways you need an else part where the other field becomes mandatory
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || g_form.isNewRecord())
{
return;
}
if (newValue != oldValue)
g_form.setMandatory("comments", true)
else
g_form.setMandatory("work_notes", true);
}
PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 12:50 PM
Thank you, but it's still not quite there.
The end result is that now Comments are mandatory, regardless whether there's a work note or not.