Business rule for field calculation

Andrew_TND
Mega Sage
Mega Sage

At the moment I have a calculation on the field to work out the percentage of a contracts consumed value.

(function calculatedFieldValue(current) {
	var consumedper = current.u_consumed_hours / current.u_total_hours*100;
	return consumedper;
})(current);

I'm no good with making business rules unless its fairly simple functional stuff e.g. if somethings x it sets another field to y.

I also want to include this into an event for email notifications.

Can anyone help it would be greatly appreciated. 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Andrew,

Where do you want that calculation to be performed?

Do you want calculation to happen when record inserted/updated? If yes then you can have this in before insert/update business rule

Sample script:

var consumedper = current.u_consumed_hours / current.u_total_hours*100;

current.<percentageField> = consumedper;

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Andrew,

Where do you want that calculation to be performed?

Do you want calculation to happen when record inserted/updated? If yes then you can have this in before insert/update business rule

Sample script:

var consumedper = current.u_consumed_hours / current.u_total_hours*100;

current.<percentageField> = consumedper;

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

That worked a treat, thank you!

How do I trigger an event from that? I'm looking for something to trigger on 50% 60% 70% 80% 90% 100%

 

Great that it worked.

Can you mark my answer as correct and helpful.

Also for triggering the notification on particular percentage reach you can use workflow.

Regards

Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader