- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2016 10:00 AM
I have 3 fields on a table that I want to calculate and populate that answer to a "total cost" field in the same table (form).
Number of Employees * Hours * Hourly Rate = Total Cost
How can I go about doing this?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2016 10:19 AM
Hi James,
You'll probably want to do a business rule to accomplish this. You could either add the script to the business rule itself or build out the function within a script include. The following is if it were in a business rule script.
Set the rule to Before. Add conditions if necessary. Check boxes for Insert and Update on 'When to run'. Check the Advanced field.
Under the Advanced tab, enter the following script:
current.u_total_cost = current.u_employees * current.u_hours * current.u_hourly_rate;
The total will update when a record saved. Let me know if you need it to run as a Client Script or want to run it from a script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 01:50 PM
Michael
I have similar case...
Question for you: when you create the business rule, do I select table = task?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 08:07 AM
I know this thread is old but i'm trying to do a similar thing. I tried modifying the example above, however one field for the calculation is on a different table ('u_item_price' (price per item)) table: u_item_type.
How would I get the value of the field from the other table in my business rule script? I've tried this: - (i'm not a scripting expert!) What am I doing wrong?
TIA
(function executeRule(current, previous /*null when async*/) {
var total = 0;
var items = current.number_of_items;
var price = new GlideRecord('u_item_type);
price.addQuery('u_item_price');
price.query();
while(price.next()) {
total = price*nights;
}
g_form.setValue('total_cost', total);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 01:51 PM
James
Which table did you select when you created the Business Rule?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2022 09:44 PM
Please have a look into this article. This might be of some help: