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).

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

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

let createDate = dep['Create date'];
const customer = dep['Customer name']; // Set this dependency from the linkedTo activities

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

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

let day = today.getDate();
let month = today.getMonth();
let 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
// Select the dep from LinkedFrom activities

let total = 0;

for (let value of dep['Total Price']) {
    total += value || 0;
}

function round(input) {
    return Math.round(input * 100) / 100;
}

return round(total);

 

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

const quantity = dep['Quantity'];
//Select product name from linkedTo activities fields
const product = dep['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

const quantity = dep['Quantity'];
const product = dep['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
// Choose Unit Price from Part catalogue(Linked From activities

function round(input) {
    return Math.round(input * 100) / 100;
}

let total = 0;

dep['Unit Price'].forEach(value => {
    total += (
        value ||
        0
    );
});

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

 

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

const quantity = dep['Quantity'];
//Select component name from linkedTo activities fields
const component = dep['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

const quantity = dep['Quantity'];
const component = dep['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 at info@hailer.com