Skip to main content

Dynamic Formulas - Practical Examples

Examples you can use and modify to use dynamic examples

Updated over a week ago

Basic Functions

Using Standard iPaaS.com Fields

Reference any field that exists in your iPaaS.com object directly in formulas. Note that custom fields are fields you create for items not natively supported by the platform.

if(Weight != null)

Checking for Empty or Null Values

Use the IsEmpty() function to check if an object is null or contains an empty string:

IsEmpty(ObjectName)   

Returns true if the object is null or an empty string ("").

Concatenating Values

Use the + operator to combine strings:

FirstName + " " + LastName

Truncating String Data

Limit string length using the Truncate() function:

Truncate(FieldFromFirstMatch(Addresses, "IsPrimaryBilling == true", "FirstName"), 15) 

Syntax: Truncate(string, length)

This example truncates the first name from the primary billing address to 15 characters, useful when target systems have field length restrictions.

Creating Conditional Logic

Write if/else statements in two formats:

Standard Format

if (A == 5) 
{
    return "A";
}
else if (B == 5)
{
    return "B";
}
else
{
return false;

Ternary Operator (Shorthand)

(A == 5 ? "A" : "B") 

Syntax: (condition ? consequent : alternative)

Working with Custom Fields

Getting Custom Field Values

Retrieve a value from a custom field in the current object:

GetCustomFieldValue(CustomFields, "Custom Field Name")  

Getting Parent Object Custom Fields

Access custom fields from a parent object:

GetCustomFieldValue(parent.CustomFields, "Custom Field Name") 

Use this on child objects, such as transaction addresses, to pull custom fields from their parent (like transactions).

Getting Child Object Custom Fields

Access custom fields from a specific child object:

GetCustomFieldValue(FirstMatch(Addresses, "IsPrimaryBilling == true").CustomFields, "Custom Field Name")

This example finds the primary billing address and retrieves its custom field value.

Handling Null Values with Coalesce

Provide default values when custom fields are empty:

Coalesce(GetCustomFieldValue(CustomFields, "Custom Field Name"), "Default Value") 

The Coalesce() function returns the first non-null value from the list. In this example, if the custom field Custom Field Name does not exist or is empty, it returns the static string Default Value.

ID and Reference Functions

Finding iPaaS.com IDs from External IDs

Convert an external system ID to an iPaaS.com ID:

var spaceportId = GetSpaceportId(CustomerPriceGroup, "Customer Category", 664);  

Parameters:

  • CustomerPriceGroup: Variable containing the external ID

  • "Customer Category": Object type

  • 664: External system ID

Finding External IDs from iPaaS.com IDs

NOTE: Any data object with an external ID is valid for conversion.

Convert an iPaaS.com ID back to an external system ID:

return await GetExternalIdAsync(ParentId, "Product", 123); 

Parameters:

  • ParentId: iPaaS.com ID

  • "Product": Table name

  • 123: Target system ID

Tip: Use the SpaceportSystemId variable to reference the current system automatically. For example, if you're creating a mapping for system 999, SpaceportSystemId will equal 999.

Finding Customer IDs by Email

Retrieve a customer's iPaaS.com ID using their email address:

var id = await iPaaSCustomerFromEmailAsync("bob@example.com");

Advanced Operations

Working with Lists

Create and manipulate lists using standard C# syntax:

Creating an Empty List

List<int> categoryIds = new List<int>();  

Adding Items to Lists

categoryIds.Add(1); 
if (A == 5)
{
    categoryIds.Add(2);
}

Filtering Records

Exclude specific records using logical operators:

!(EmailAddress == "email1@example.com") && 
!(EmailAddress == "email2@example.com") &&
!(EmailAddress == "email3@example.com")

This example filters out three specific email addresses. Use iPaaS.com field names in FROM mappings and external system field names in TO mappings.

Preserving Existing Field Values

Keep existing values when they exist, only updating when empty:

if(string.IsNullOrEmpty(DestinationValue.Email))
return SourceEmailAddress;
else
return DestinationValue.Email;

Use the DestinationValue object to reference current values in the destination system.

Error Handling and Process Control

Stop processing with custom error messages:

var external = await GetExternalIdAsync(ParentId, "Product Category", SpaceportSystemId); 
if(!IsEmpty(ParentId) && IsEmpty(external))
    throw new Exception("Parent category must be transferred first");
else
    return true;

Throwing exceptions halts the transfer process and logs your custom error message, which helps with monitoring and automatic retry scenarios.

Assigning Categories

Create category associations for customers or products:

NOTE: Use this in TO iPaaS.com mappings. In this example, CustomerPriceGroup is the category name from your JSON data, and 664 is your integration's subscription ID.

if (CustomerPriceGroup != null) 
{
    var spaceportId = GetSpaceportId(CustomerPriceGroup, "Customer Category", 664);   
    if(spaceportId != null)
    {
        List<dynamic> dynamicList = new List<dynamic>();
        dynamic obj = new System.Dynamic.ExpandoObject();
        obj.Id = spaceportId;
        dynamicList.Add(obj);
        return dynamicList;
    }
}
return null;

For products, change "Customer Category" to "Product Category" in the GetSpaceportId function call.

Did this answer your question?