Custom Formulas

Formstack custom formulas can be used in a few different places within Formstack to generate custom values. Custom formulas are currently supported by the following Formstack features:

  • You can dynamically populate fields with custom formula results using the 'Populate' action in the rule editor.
  • You can set a custom file name for PDF copies of your form.
  • You can set a custom file name for files uploaded within a File Upload general field.
  • You can set a custom formula for a field's default value.

Custom formulas use basic Javascript syntax. To write custom Javascript for your populate action, simply wrap the Javascript in double braces. For example, to populate a field with today's date, you can use the following formula and enter it as the default value:
 

{{TDAY()}}



You can also include fields from your current form as part of your formula as well.

First, find the "Id" of the field you are working with, by right click + Inspecting the input field that you wish to reference. For example, if I wanted to Reference the "Last Name" field from the contact object:


You would write [[Contact.LastName]]

This can have several applications, for example if you want to populate an Account Name field with the First name and Last Name of the user filling out the form, you could create a rule like this:



You can also do basic arithmetic. Here's an example of a formula that outputs 10% of a contact's salary:

{{[[Contact.Salary]]*0.1}}

Wrap your formula in curly braces {{ }} for Javascript functions.

Here are some other useful formula samples you can try for yourself:  
Generate a timestamp {{new Date().toISOString()}}
Get a contact's first initial and last name {{"[[Contact.FirstName]]".charAt(0);}}[[Contact.LastName]]
Calculate sales tax {{[[Order.TotalAmount__c]]*0.15}}
Generate a random number between 1 and 1000 {{Math.floor((Math.random() * 1000) + 1)}}
Call custom functions defined in Custom Javascript window {{CalculateAverage([[MyObject.Value1__c]],[[MyObject.Value2__c]],[[MyObject.Value3__c]])}}
Output today's date {{TDAY()}}

Note: Custom formulas will only work on your published forms, not when using the preview option. 

Was this article helpful?

https://cdn.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete