1. Help Center
  2. Function Fields

How to use Function Fields to build a price calculator in Hailer

Learn how to use Function Fields to calculate sales order prices automatically.

Function Field is an option that you can enable for most field types (e.g. text, date, and numeric). It allows you to type in with JavaScript a set of rules for returning a certain value or result (e.g. an automatically generated title for an activity or the total price of an order).

Function Fields are available for Enterprise licences. Contact us for more information! info@hailer.com

You can use multiple Functions Fields together to build a full-blown system for tracking work hours or calculating invoice amounts, for example.

Example: Price Calculator

Here's an example. You have a company that manufactures and sells computer desks. You want to build a sales process where you can calculate the total price of an order automatically. 

 

function fields

Processes and Datasets

Create one process ("Sales") and six datasets ("Customers", "Sales Order Rows", "Products", "Part Catalogue", "Components", and "Man Hours"). The diagram below shows which of them are linked together using the activity link field type.

 

function_fields_processes_and_datasets

Linking activities allows you to quickly select activities as values from other processes and datasets. This can be a customer from a dataset of customers, like in the activity link between the "Sales" process and "Customers" dataset above.

 

Field Types

Add fields to processes and datasets. Below are screenshots of the fields and their field types for the "Sales" process and all the datasets. Notice that some of the fields have the "Function Field" option enabled. When you enable it, an "Edit Function" button appears below the checkbox.  

 

"Sales" Process

function_fields_field_types_sales

"Customers" Dataset

function_fields_field_types_customers-1

"Sales Order Rows" Dataset

function_fields_field_types_sales_order_rows-1

"Products" Dataset

function_fields_field_types_products-1

"Part Catalogue" Dataset

function_fields_field_types_part_catalogue

"Components" Dataset

function_fields_field_types_components

"Man Hours" Dataset

function_fields_field_types_man_hours

Activities

Now you have all the processes, datasets, and their fields set up. Next, add and price all the things you need in order to deliver your products and services. As a company that manufactures and sells computer desks, you need to list out the work and components needed to build computer desks. Your computer desks need assembly work, screws, desk boards, and desk legs. 

Go to the "Man Hours" dataset and add "Assembly work" with a price of 60 euros per hour.

 

function_fields_activities_man_hours

Next, go to the "Components" dataset and add "Screws" with a unit price of 0.30 euros, "Desk Boards" with a unit price of 100 euros, and "Desk Leg" with a unit price of 20 euros.

 

function_fields_activities_components

To come to think of it, you don't want to have to calculate the number of man-hours, screws, desk boards, and desk legs separately every time you add a new order. It's way too slow in the middle of a sales call. It's best to define how much work and what components go into building a computer desk. And define what is the total price of a computer desk.

Go to the "Part Catalogue" dataset and add the catalogue below.

 

function_fields_activities_part_catalogue

You only need to write the "Quantity" of each item.  The value for "Product" and "Component" you'll select from a dropdown menu because you are using the linked activity field type to link to "Products", "Components" and "Man Hours" datasets from the "Part Catalogue" dataset.

Notice how the value of the "Product" field ("Computer" Desk") is written in blue.  Also the value of the "Component" field ("Screw"). They are links that can also be used to navigate to linked activities.  

The values for "Title" and "Total price" will be generated automatically after you have added JavaScript to their Function Fields. Notice how the "Title" and "Total Price" fields have a function symbol ("f") next to them. 

 

function_fields_activities_part_catalogue_opened

You still need to piece your computer desks together. Go to the "Products" dataset, add a new activity and give it the title "Computer Desk". 

 

function_fields_activities_products

Again, the value for "Unit Price" will be calculated automatically after you have added JavaScript to the Function Field.

 

function_fields_activities_products_opened

 

You can browse the full list of components under the linked activities tab. The list, the price of each component, and the total price of a computer desk can be updated automatically by using linked activities and Function Fields.

As your computer desk company, prices, and offering evolve, you don't have to make numerous updates manually. Your sales team will always have the right prices automatically.

 

function_fields_activities_products_opened_linked_activities

Finally, add your customer list. Go to the "Customers" dataset. Writing the name of each customer is enough in the example.

 

function_fields_activities_customers-1

Don't touch the "Sales Order Rows" dataset at this point. Activities will be added to the dataset automatically, as you start adding orders in the "Sales" process. In the future, the dataset will look something like in the screenshots below.

 

function_fields_activities_sales_order_rows

function_fields_activities_sales_order_rows_opened

Functions

To return certain values or results automatically, add JavaScript to your Function Fields.

 

function_fields_edit_function

 

"Sales" Process, "Title" Field - Generate Title

var createDate = row['Create date'];
var customer = row.Customer.name;

if (!createDate || !customer) {
   return 'Create date or customer is missing';
}

var today = new Date(createDate);
today.setTime(today.getTime() + 3 * 60 * 60 * 1000)

var day = today.getDate();
var month = today.getMonth();
var year = today.getFullYear();

month += 1;

return (year + '/' + month + '/' + day + '-SO' + '-' + customer);

 

"Sales" Process, "Total Price" Field - Calculate Total Price

// Calculating the sum of a field present in activities linked to current activity

var total = 0;

for (i = 0; i < row.$.linkedFrom.length; i++) { // Loop through array of activities linked to current activity
var amount = row.$.linkedFrom[i].fields['Total_price']; // Take value from field called Total value
if (amount && row.$.linkedFrom[i].processId === '5f34dd9b81f8074d81297858') { // Sales Order rows process ID
total += amount; // Sum to total amount if amount exists
}
}

return (Math.round(total * 100) / 100); // Show two decimals in result if present

 

"Sales Order Rows" Dataset, "Title" Field - Generate Title

var quantity = row['Quantity'];
var product = row['Product'].name;

if (quantity && product) {
   return quantity + ' x ' + product;
} else {
   return 'Quantity or product is missing!'
}

 

"Sales Order Rows" Dataset, "Total Price" Field - Calculate Total Price

var quantity = row['Quantity'];
var product = row['Product'];

return Math.round(quantity * product.fields['Unit_price'] * 100) / 100;

 

"Product" Dataset, "Unit Price" Field - Calculate Unit Price

// Calculating the sum of a field present in activities linked to current activity

var total = 0;

for (i = 0; i < row.$.linkedFrom.length; i++) { // Loop through array of activities linked to current activity
var amount = row.$.linkedFrom[i].fields['Total_price']; // Take value from field called Total value
if (amount && row.$.linkedFrom[i].processId === '5f34dda081f8074d81297869') { // Part catalogue process ID
total += amount; // Sum to total amount if amount exists
}
}

return (Math.round(total * 100) / 100); // Show two decimals in result if present

 

"Part Catalogue" Dataset, "Title" Field - Generate Title

var quantity = row['Quantity'];
var component = row['Component'].name;

if (quantity && component) {
   return quantity + ' x ' + component;
} else {
   return 'Quantity or component is missing!'
}

 

"Part Catalogue" Dataset, "Total Price" Field - Calculate Total Price

var quantity = row['Quantity'];
var component = row['Component'];

return Math.round(quantity * component.fields['Unit_price'] * 100) / 100;

 

function_fields_ready 

 

Your Price Calculator is ready. To create a pdf print of your offer, you can use the Hailer Document Generator. We will build you a document template with your logo and details.

Would you like to learn more about function fields or the document generator? Contact us: info@hailer.com