Skip to main content

Example Functions

Example iPaaS.com functions

Updated over 2 weeks ago

General Usage

iPaaS.com uses a C# based interpreter for dynamic formulas. Many C# tutorials are available online to help you understand this formatting. One example is https://www.w3schools.com/cs/index.php. Focus on learning these key sections: Syntax, Variables, Data Types, Operators, Strings, and If…Else sections.

Basic Functions

Use a standard iPaaS.com field in a formula

if(Weight != null)

You can directly use any field that exists in your iPaaS.com object.

Check for empty or null values

(IsEmpty(ObjectName)

Checks an object and returns true if the object is null or an empty string (“”).

Concatenate 2 or more values

FirstName + " " + LastName

Use the + operator to concatenate strings.

Truncate string data

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

If a system has a maximum length allowed for a field, the Truncate(string, length) function returns the first X number of characters from the string to keep the string under the max length. This example truncates the first name from the primary billing address to 15 characters.

Create If/Else statements

You can write conditional logic in normal C# supported formats in two ways:

Standard format

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

Shorthand format (condition ? consequent : alternative)

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

Working with Custom Fields

Get a value from a custom field

GetCustomFieldValue(CustomFields, "Custom Field Name")

This retrieves the value stored in a custom field. The field must exist in your current data type.

Get a value from a parent object’s custom field

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

Where the name of the field is Custom Field Name is the name of the field. This field must exist on the parent data type where this field is used. For instance, this could be used on a transaction address that pulls a custom field from the transaction.

Get a value from a child object’s custom field

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

First locate a single child object using the FirstMatch function. There are other ways of doing this, and if there are multiple matching child objects, FirstMatch will return the first match it finds, which may not be what you want. Once located, using the GetCustomFieldValue function against its CustomFields collection is similar to other examples above.

Handle null values with Coalesce

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

The Coalesce function returns the first non-null entry in 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

Find an iPaaS.com ID using an External ID

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

This returns the iPaaS.com ID for a record based on its ID in another system. The above example returns the ID for the customer category in system 664 with whatever external ID is contained in the CustomerPriceGroup variable.

Find an External ID using iPaaS.com ID

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

The GetExternalIdAsync(Object id, Object tableName, Object systemId) function takes an iPaaS ID and table and returns the external ID for the specified system. The example above searches for the product with the iPaaS.com ID contained in Parentid and returns the external ID saved for system 123.

Note: You can use the Spaceport SystemId variable to automatically reference the current system. For example, if you're creating a mapping for system 999, then Spaceport SystemId will always equal 999.

Find a Customer ID using an email address

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

The iPaaSCustomerIdByEmail returns the iPaaS.com ID for the customer by providing an email address.

Advanced Operations

Create and use lists

Lists can be created in standard C# style.

Start with a new, empty list:

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

Add items to the list using the .Add() function.

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

Filter out specific records

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

This checks to see if the value in the field matches and excludes specific values. This example filters out three specific records: EmailAddress is email1@example.com, email2@example.com, and email3@example.com.

Use the iPaaS.com field on FROM mappings and the external system field in the TO mappings.

Keep the existing value of a field

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

Reference current values in a destination object with the DestinationValue object. This example checks if a customer has an email address set, and if it does, it leaves it in place. If the customer doesn’t have an email address, it sets it.

Stop a process with an error message

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;

Sometimes you need to stop a a process, such as applying a dynamic formula or mapping a collection filter if a condition isn’t met. For example, if you want to transfer a product category with a parent category assigned but find that the parent doesn’t exist, the transfer doesn’t make sense. You can raise an exception, which halts the transfer and logs the error you provide. This alerts the team monitoring errors and may fix itself automatically if the parent category gets imported on automatic retry.

Assign a Category to a Customer/Product

Note: Use this on a TO iPaaS.com mapping. In this example, 'CustomerPriceGroup' is the category name from your incoming JSON data, and 664 is your integration's subscription ID.

GetSpaceportId to Product Category.

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;

This example creates a category association. It finds the iPaaS.com. ID for a category and creates a relationship object. For products, change Customer Category in the GetSpaceportId to Product Category.

Did this answer your question?