businesss rule to check user is vip

hemasree kanduk
Tera Contributor

i need to write an after business rule to check whether the caller of the incident is VIP or not and if yes it should populate the caller in the description.

3 REPLIES 3

Sai Kumar B
Mega Sage
Mega Sage

@hemasree kanduk 

Try the following in the before Business rule
Filter condition
caller_id.vip=true

Code

current.setValue('description', current.getDisplayValue('caller_id'));

Sagar Pagar
Tera Patron

Hi @hemasree kanduk ,

 

You have to write a Before insert/update business rule instead of After.

 

Try this sample scripts with condition as Caller ISNOTEMPTY.

(function executeRule(current, previous /*null when async*/) {

	if(current.caller_id.vip == true){
		// add your scripts here
		
		current.short_description = current.caller_id.getDisplayValue() + " - " + previous.short_description;
	}
})(current, previous);

 

Thanks,

Sagar Pagar

The world works with ServiceNow

kamlesh kjmar
Mega Sage
Mega Sage

Hi @hemasree kanduk ,

 

Could you please elaborate your use case. As you mentioned in your problem statement "You need to write an after business rule". This will not make sense as after BR executes after your data is saved in database. Now if you make any change in description after saving data in table, it will be useless untill you do not save it again.

1. If your use case is "Whatever end user writes in short description field, on submitssion of form if calller is VIP then caller name should appear before description in that case you can use below script in a Before insert and update BR :

For condition to check if caller is VIP always prefer to use condition builder wherever possible. Here you will have to dot walk to get VIP ( Caller.VIP)

 

kamleshkjmar_1-1666784758418.png

 

 

 

 

 

 

current.description = current.caller_id.getDisplayValue() + " : " + current.getValue("short_description");

 

 

 

 

2. If your use case is "If calller of incident is VIP then caller name should appear in description" in that case you can use below script in a Before insert and update BR

 

 

 

 

current.description = current.caller_id.getDisplayValue();

 

 

 

 

If your use case is anything else, please let us know so that we can help better

 

I Hope this helps.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh