Documentation

Javascript Step

The Javascript step can be used to add JavaScript functions to your workfows.

This allows you to programmatically process the output of the previous steps and can be useful in many cases.  Instead of writing a lot of steps to manipulate the data these steps help you to keep the workflow easy.

For example

Example 1: 

Let’s say you want to sync Contacts from Shopify to Salesforce.  The mapping of contact data is easy for text fields but can get hairy for lookups like States, Countries, and others.  Doing it in steps will requires creating 100s of steps, one for each lookup: 

  • If ShopifyContact.country is “US”, map it to SalesforceContact.Country “United States”
  • If ShopifyContact.State is “NJ”, map it to SalesforceContact.State  “New Jersey”

Bit if you have access to JS code you can just create a simple Dictionary and use it for mapping

var shopifyToSfState = { “NJ”: “New Jersey”, “NY”: “New York”, }

And when you need to map data you do:

Salesforce Contact State   <<map from>>    <shopifytoSfState[shopify contact. state]>

That’s it.  

Your flow can stay nice and simple and not be polluted with 100 steps just to map one lookup field.

We decided to add a code step in pandaflow so that it is easier to add these types of logic within the workflow when it is needed.

 

Example 2:  

Nested loops are very common when you are dealing with data of any complexity such as orders.  For example, if I want to get all the orders from Shopify and create Salesforce Opportunities you would need to create an outer loop to iterate through the orders and then an inner loop that would iterate the order items for each order to convert them to salesforce opportunity items.

 In code, it would be pretty straightforward.

Loop (shopifyOrder in shopifyOrders) { Map shopifyOrder fields to sfOpportunity field Loop (shopifyOrderItem in shopifyOrder) Map shopifyOrderItem to sfOpportunityItem }

In PandaFlow it is pretty simple. You can create as many loops and nested loops as you like. And you can also introduce Javascript snippets for any complex mappings.