Clear a field on incident when it's state updates to Cancelled

RC19
Tera Contributor

Hello All,

 

I have to clear a field when state of incident is updated to cancelled, please let me which BR is to written as it is not better practise to use current.update() in BRs . Which is the best way of achieving this as per servicenow best practices ?

3 REPLIES 3

AshishKM
Kilo Patron
Kilo Patron

Hi @RC19 , 

You dont need to use current.update() in BR, just mark field emtpy using the curren object. 

Only issue i can think of, any mandatory field at DB level may not allow BR to save the current object.

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Sandeep Rajput
Tera Patron
Tera Patron

@RC19 You can easily achieve this via an onSubmit client script, no need to create a business rule for this case.

 

Here is an example of the onSubmit client script.

 

function onSubmit() {

    var state = g_form.getValue('state');
       if (state == '8') { //8 is cancelled
        g_form.clearValue('location');//Assuming you need to clear the location field.        		
    }
}

swathisarang98
Giga Sage
Giga Sage

Hi @RC19 ,

 

You can write simple onchange client script to clear the value of any field when state change or updated to cancelled,

swathisarang98_0-1711739754409.png

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
		if (newValue == 8){
			g_form.clearValue('company');
		}

   
}

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang