--- title: "Apply custom expression (Field option)" slug: "apply-custom-expression-field-option" description: "Learn to use expressions for modifying values in mapping, combining fields, and calculating prices effectively in your integration design." tags: ["Task topic"] status: "update" updated: 2026-10-05T12:04:06Z published: 2026-10-05T12:04:06Z canonical: "docs.staedean.com/apply-custom-expression-field-option" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.staedean.com/llms.txt > Use this file to discover all available pages before exploring further. # Apply custom expression (Field option) You can use an expression to modify the value. As a variable in the expression, you can use a: - Source field or target field from any record of the applicable document. If you use a field from another record than the current record, make sure this record is mapped before the current record. - Mapping variable that is defined for the message. **Examples:** You can use an expression to: - Combine two fields. For example, you can make a contact location name specific by combining it with the purpose. The expression can be: Description+'-'+Purpose. This results in, for example: Shop Main Street-Financial. - Calculate the unit price based on the quantity and line amount on a purchase order confirmation. The variables are from the source record: Qty (PurchLine, PurchQty field) and Amount (PurchLine, LineAmount field). The expression is: Amount/Qty. > [!NOTE] > **Note** > > - Usually, you use string and real values as variables. > - Date calculations are not supported. > > For more information on expressions, refer to: [Expression](https://docs.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?redirectedfrom=MSDN&view=net-5.0#System_Data_DataColumn_Expression). ### Steps 1. Click **Connectivity studio - Integration Design**. 2. On the **Message** tab, in the list, find and select the desired message. 3. Click **Edit**. 4. In the **Mapping** section, in the **Target record** pane, in the list, find and select the desired target record. 5. On the **Mapping** tab, on the **Field mapping** tab, in the list, find and select the desired field mapping. 6. Click the **Field options** tab. 7. Select the **Custom** check box. 8. Add a variable line for each variable that is used in the expression. In the **Variables** pane, click **New**. 9. In the **Variable** field, type the variable name exactly as used in the expression. 10. Define if the variable is linked to a field in the source document or target document. In the **Record origin** field, select an option. 11. Define the document record to which the variable is linked. In the **Record** field, enter or select a value. 12. Define the document record field to which the variable is linked. In the **Record field** field, enter or select a value. > [!NOTE] > **Note** > > The field type, as defined for the document record field, is shown as well. 13. During a message run, you can use mapping variables to temporarily store values. You can write (calculated) values to a mapping variable. Later, during the same message run, you read the value from the mapping variable for use in a custom expression. In the **Mapping variable** field, enter or select the mapping variable whose value is used in the expression. > [!NOTE] > **Note** > > Make sure the field mapping in which the mapping variable is written is done before the field mapping for which you define the custom expression. 14. You can indicate how the variable value must be handled in the expression, regardless of the document record field type. In the **Variable type** field, select an option. 15. You can define the language in which the variable is expressed. In the **Language** field, enter or select a value. 16. In the **Expression** field, enter the expression, using variables. 17. Before the output value of the custom option is determined, you can apply a type conversion to the value that is returned by the custom expression. In the **Type conversions** field, enter or select a value. > [!NOTE] > **Note** > > You can test the created expression. To do so, click **Test expression**. On the dialog, fill in the values of the variables and click **Execute**. 18. Close the page. > [!NOTE] > **Note** > > Applying custom expressions can affect message performance. Therefore, only apply a custom expression if required and keep it as simple as possible. > > The following example shows a more complex custom expression. Based on the value of 'netPrice' from the source record and 'taxPerc' from the target record, the tax amount is calculated. > > ![Variables and expressions for calculating extended discount and tax percentage in a document.](https://cdn.document360.io/da662430-6a41-47b1-8c7e-7e4ac37a9756/Images/Documentation/FieldMapping_Expression_Example1.png) ## Related - [Define field options](/define-field-options.md)