Make Worknotes Mandatory , if Impact or Urgency gets updated

Pooja Khatri
Tera Contributor

Hi All ,

 

I have a requirement , where I need to make work-notes mandatory when the values of impact or urgency field changes.

The default value of Impact = 5 and Urgency  = 5 which will be set when the incident form is opened , I want the work notes to be mandatory only if the default values for impact or urgency is changed . 

 

If the Save or Update buttons are clicked after changing the Impact or Urgency values and before typing a Work note, then an error should be displayed . . . The following mandatory fields are not filled in: Work notes .

 

How can I implement this scenario  ? 

14 REPLIES 14

Weird
Mega Sage

You'll need to create a Client script that is onChange type and checks impact and another one which checks the urgency field.

Weird_0-1713765087652.png

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '' || newValue == '5') {
      return;
   }

   g_form.setMandatory('work_notes', true);
   
}


Basically this just checks if the newValue is anything other than empty or 5 and makes work_notes mandatory.
You'll also get the mandatory error automatically when trying to save if you haven't filled mandatory fields, so you don't have to worry about that.

Hi @Weird - will this script run if after changing the default values one and then clicking on save and then again making it as 5 again during that time will it give work notes as mandatory , ideally as per requirement it should give as mandatory .

On the client script you set the field "Field name" to the field you want to follow.
In this case one  client script would have Impact and the other Urgency on those field.
Now the client script will run whenever you change the field value.

If you want the field to always be mandatory when the impact or urgency is changed then you could try the following

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '' || newValue == oldValue) {
        if (newValue == oldValue) {
            g_form.setMandatory('work_notes', false);
        }
        return;
    }

    g_form.setMandatory('work_notes', true);

}

 newValue = oldValue makes sure that we are actually changing the value. So if you for example go from 5 to 3 and back to 5 it will set the work notes back to non mandatory. 
Otherwise any change will set work_notes as mandatory.
newValue is the value you selected now and oldValue is the value that is stored in the database.
So if you open up a form that has impact as 3 then oldValue will be 3 until you save the record with something else.

Hi @Weird - I tried with the script it worked for scenarios where the default value was changed from 5 to 2 and then back to 5 before saving the form , but for scenarios where the the form is saved then the value of impact or urgency is changed to 2 during that time it gives work notes as mandatory but for scenarios where again the impact or urgency is changed back to 5 during that time too it should give as worknotes mandatory but its not working there .. how can I fix that part ?