How to set a Priority field value onLoad only

ss123
Tera Contributor

Hi!

 

We have a requirement where we need to set the Priority to field to --None-- (this is from the Dropdown with None) when a case form is newly created and HR Service = "HRServ1" (sample only)

 

I achieved this using UI Policy but the problem is, when we changed the Priority value to other options then click  Save or Update button, it goes back to Priority value "--None--"

 

Thanks in advance

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi UI Policy will not work for this since it will run on each onload, you can go for before insert Business rule and set priority to none as this BR will run only once that is during case creation.

HarishKM_0-1690339127552.png

HarishKM_1-1690339140571.png

 

Regards
Harish

View solution in original post

11 REPLIES 11

DanielCordick
Mega Patron
Mega Patron

How is your UI policy set up? Sounds like you still have something running onLoad 

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response helped in any way 

@DanielCordick this is the script in UI Policy. I've set the condition per requirement in When to Apply.

SabrinaSalazar_0-1690333884818.png

Thanks

Make sure your UI Policy condition when to apply is correct.

another way include a if condition to check and then set to none inside if

Regards
Harish

Tony Chatfield1
Kilo Patron

Hi, I think you have 2 options
Client API has a  isNewRecord() method to test if the record is 'new'
GlideForm | ServiceNow Developers
Also if the record is new then the sys_id will be -1
You should be able to test the state of your record using either of these in your script
and only apply your priority when the record is new.
I would recommend using isNewRecord() and the API documentation example is everything you will need.

function onLoad() {
   if(g_form.isNewRecord()){
      alert('New Record!');
   }
}