No "change" operator in UI policy

JordyZ
Mega Sage

Hello,

 

On the incident form, I have the additional comments set to mandatory when the state is on hold (through UI policy). The problem is that the comments field stays mandatory while on hold, even when I just want to update the category field for example. 

 

So I was thinking to use a change operator in the UI Policy so comments are only mandatory when the state changes to on hold, and not while it is on hold. The thing is, there is no change operator in UI policy. 

 

I've found a similar thread that advises using an onChange client script instead of UI policy.

 

https://www.servicenow.com/community/developer-forum/no-quot-changed-quot-operator-in-ui-policy-cond...

 

However, I'm new to all of this and have no idea how to code it. Anyone able to help? Thanks in advance.

1 ACCEPTED SOLUTION

AnubhavRitolia
Mega Sage
Mega Sage

Hi @JordyZ 

 

Please try below Client Script:

 

AnubhavRitolia_0-1673890392500.png

 

 

 

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

	if(newValue=='3') {
	g_form.setMandatory('comments',true);
	} else {
		g_form.setMandatory('comments',false);
	}
   
}

 

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

3 REPLIES 3

AnubhavRitolia
Mega Sage
Mega Sage

Hi @JordyZ 

 

Please try below Client Script:

 

AnubhavRitolia_0-1673890392500.png

 

 

 

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

	if(newValue=='3') {
	g_form.setMandatory('comments',true);
	} else {
		g_form.setMandatory('comments',false);
	}
   
}

 

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

This did the job, thank you!

 

If you have the time, I have another problem, it's regarding SLA notification and how to get time zone of the caller. Someone has given a solution but it's not working for me, unfortunately. If you could take a look, would be much appreciated.

 

https://www.servicenow.com/community/developer-forum/how-to-have-notification-sla-in-different-timez...

surbhi9
Tera Contributor

You can write an onChnage client script on State field.

 

  if (g_form.getValue('state') == '3') {
        g_form.setMandatory('comments', true);
    }

 

 

Please mark Helpful/Correct, if helped.

Thanks!