Formulas
Users can use formulas to transform data using AppConnect. Formulas allow users to easily work with and format data. Formulas in AppConnect are whitelisted Ruby methods. Not all Ruby methods are supported, but you can always reach out to us to add additional formulas to the whitelist. Syntax and functionality for these formulas are generally unchanged.
AppConnect allows you to work with the following standard data types:
Formula mode
To start using formulas, you need to be in formula mode. Formula mode needs to be switched on at the field level, and most input fields support formula mode. To toggle from text mode into formula mode, click on the text/formula mode switch button. This also changes the type icon of the input field into the fx icon.
When the input field is toggled into formula mode, the string type input field changes icon from String type to fx type.
![e91a3ca5-dded-4d63-b3a4-caa472d8e365.gif](https://s3.amazonaws.com/insightly.userfiles/36409/VI6LWS/50fa3ee9-c1a4-42cd-bf4f-ff873134b804.gif?AWSAccessKeyId=AKIAJRNAGB7KJX37RU4Q&Expires=1725753323&Signature=9ppe2J79NZ4R%2FxUlxAybZGhiL1E%3D)
Using the formula editor
In formula mode, the formula editor provides a set of whitelisted formulas available for data transformation/manipulation, and provides additional help on how to use these formulas.
Filter formulas displayed by data type
The formula editor should always display the type specific formulas for your datapills.
When a string type datapill, the pill Full name, is dropped into an input field in formula mode, the formula editor prompts for a period . to be added behind the pill, as per Ruby syntax. Subsequently, the editor shows the list of formulas applicable to strings.
![8927b76b-cc27-4f95-88b3-38effebeacdf.png](https://s3.amazonaws.com/insightly.userfiles/36409/12DJFT/9c5f4abd-9219-4499-a99a-70e7e31573af.png?AWSAccessKeyId=AKIAJRNAGB7KJX37RU4Q&Expires=1725753323&Signature=ro8a7BX7xfQEjd6%2FeDXNCSHh%2BwE%3D)
Similarly, when a date type datapill is dropped into the input field in formula mode, the formula editor prompts for a period . to be added behind the pill, subsequently displaying the list of formulas applicable to dates.
![5e59af28-10ae-4188-94e7-876510676869.png](https://s3.amazonaws.com/insightly.userfiles/36409/1QMO4F/abaac376-cf77-4563-8bee-3cad421208e3.png?AWSAccessKeyId=AKIAJRNAGB7KJX37RU4Q&Expires=1725753323&Signature=2%2BuKR8rUmZ3TSw7ou%2FZiJovIoJ0%3D)
When there is no datapill within the input field, the general structure of formulas will display, but typing will automatically begin to display other formulas and operators which can be used.
![b982890e-4f1e-47d6-bfed-8ba7bcb6e09c.gif](https://s3.amazonaws.com/insightly.userfiles/36409/S7GFAF/237f9af4-2c8d-42d3-8682-294d80334c42.gif?AWSAccessKeyId=AKIAJRNAGB7KJX37RU4Q&Expires=1725753323&Signature=vqoG5PJYY1Mcojk2V1olgG2E5Hc%3D)
Formula hints and syntax
When a formula is selected to be used, it will be auto-completed in the input field. An explanation of the formula's function, as well as its syntax, will be provided.
![2baac954-e337-4541-83a0-331b967f9982.gif](https://s3.amazonaws.com/insightly.userfiles/36409/XA4EPY/6e565bc4-294d-4f6b-a16d-1cff516e06c3.gif?AWSAccessKeyId=AKIAJRNAGB7KJX37RU4Q&Expires=1725753323&Signature=qxWoL03rSpDV4nNBG9hgpUFAhNA%3D)
Text VS formula mode
In text mode, text and pills can be mapped into the input fields easily, and they will result in a text that looks exactly like what is formed. On the other hand, text needs to be explicitly formatted in formula mode.
Let's use an example of a recipe that sends an email to new leads in Insightly. If a new lead called Madison Diaz is created, we wish to send the following email:
1Hi Madison,23Thanks for joining our mailing list! We're excited to have you!4
In text mode, the Message can simply be formed like this:
![271f6e80-f5c3-4828-a332-915f0c955991.png](https://s3.amazonaws.com/insightly.userfiles/36409/ZMZCTL/8dacce35-2149-4e2a-a09b-232ac8e594b4.png?AWSAccessKeyId=AKIAJRNAGB7KJX37RU4Q&Expires=1725753323&Signature=qIDO40Eoz%2FSA%2Bd6NH7fLtlUXh6s%3D)
In formula mode, text must have proper string syntax:
![012068b8-c929-4172-9981-e3f3b1b67a57.png](https://s3.amazonaws.com/insightly.userfiles/36409/AX6ZZU/ed3cba52-3dac-4ec0-837a-1b00b0a7182c.png?AWSAccessKeyId=AKIAJRNAGB7KJX37RU4Q&Expires=1725753323&Signature=LU7jomnJuit8%2B88aqfPXG%2BQPlEc%3D)
Conditionals
You can conditionally execute formulas using Ruby's ternary syntax (popular shortcut for if-else statements). Ternary syntax are of the form:
1condition ? expression1 : expression22
Behaviour
condition
A boolean expression that evaluates to true or false.
expression1
Returns this expression if condition is true.
expression2
Returns this expression if condition is false.
Conditional formula example
In the following example, we conditionally pass in either the Full name or First name into the Message input field.
Checks if Full name is present. Outputs Full name if present, or First name if not present.
Here is a detailed explanation of what the ternary formula does:
Full name.present? will check if the Full name pill has a value . If it has a value, it evaluates to true. If it has no value, it evaluates to false.
The second ? in the formula separates the condition to evaluate from the expressions to return. Note, the first ? is part of the .present? formula whilst the second ? is separated with a space character and is part of the ternary syntax.
If there is a value in the Full name pill when the job is ran, the value for Full name will mapped to the Message input.
If there is no value in the Full name pill when the job is ran, the value for First name will be mapped to the Message input. Of course, if there's also no value in this First name pill, the job will fail at this step if Message is a required input field.
Safe Navigation Operator
Checks if the input is valid. If true, it performs a specified operation on the input data.
Syntax
Input and operation
Input - An input datapill. It can by any datatype.
Operation - If the input is not null, this formula will be applied to the input data. This formula must be compatible with the input datatype.
How it works
The Safe Navigation Operator (&.) checks if the input data is valid. It returns a null value if the input data is null or undefined. If the input is valid, it will perform the operation specified by the operation argument. It enables you to write simpler expressions to handle null values.
Before
The Created Date datapill needs to be converted to a date datatype using the to_date formula. Since the formula will encounter an error if the datapill contains null value, you would have to use a ternary expression to work around this logic.Using ternary conditions
After
Use the &. operator instead. The safe navigation operator allows you to manage cases where Created Date contains a null value, while writing a simpler formula expression.Using Save nagivation operator
Safe Navigation example
User wants to split an employees full name into their first and last name and then separate these by a comma. It is possible that the Full Name datapill may have a null value. The &. operator makes it easy to write a simple expression for this.
![d05352c4-0590-45c8-9976-064997a07b0b.png](https://s3.amazonaws.com/insightly.userfiles/36409/NTE36F/8f08c7e4-a8eb-4e10-bf64-7e49d2edc503.png?AWSAccessKeyId=AKIAJRNAGB7KJX37RU4Q&Expires=1725753323&Signature=AUjNW6e7X6RzyUFuM97yU6MxpOs%3D)