1. Help Center
  2. Function Fields

Frequently used functions

This article contains examples of common functions

1. Calculate the sum of linked activities

let total = 0;

// Define allowed names of workflows or datasets
const allowedNames = [
   'Time Tracker',
   'Tasks',
   'Product Development',
   'Development Tasks'
];

// Loop through the array of linked activities and match against allowed names
for (let i = 0;i < row.$.linkedFrom.length;i++) {
   total += (
       allowedNames.includes(row.$.linkedFrom[i].processName) &&
       row.$.linkedFrom[i].fields['Time_spent'] || 0
   );
}

// Return the sum or null if 0 (false)
return total || null;

2. Calculate the actual project margin in percent (%)

// Fetch project budget and costs, default to 0 if empty
const budget = row['Project budget'] || 0;
const costs = row['Project costs'] || 0;

// If there is a budget, return margin, otherwise return null
return budget && Math.round(100 * (budget - costs)/budget) || null;

3. Automatic naming of project activity 

// Fetch customer name when customer is selected in an activity link field
const customer = row['Customer'] && row['Customer'].name || 'Customer not selected';

// Fetch project name
const project = row['Project name'] || 'Project name missing';

// Return customer and project name
return customer + ' - ' + project;

4. Fetch unit price of the product but prevent a field from auto-updating and allow manual overwrite

// Fetch unit price if product is selected, fall back to null
const unitPrice = row['Product'] && row['Product'].fields['Unit_price'] || null;

// Return current value if not 0 or null
// (the field where this function is located is named Unit Price)
// Otherwise return product unit price
return row['Unit price'] || unitPrice;

5. Taking the values of two date fields into one date range field

return {start:row['Start date'], end:row['End date']};

Take a look at more examples in Bitbucket