Hello everyone, this article is for all users who wish to sync up objects with line items between your applications. Whether they are order from your Shopify to your QuickBooks invoice, or your QuickBooks sales receipt to your Salesforce Order Products, when dealing with line items, here are the basics and things that you will need to watch out.
Q : "I am getting duplicated line items in my order. Why is that so?"
Q : "How do I add line items to my invoice?"
To be able to add line items to any objects, first and foremost you will need the action that runs along the line of "Add Line Item". Without it, you will not be able to perform any line item addition.
Secondly, adding line items usually involve adding an item from that specific application. If you want to add a line item that may not be available on that application, that will throw you an error. You will need to have steps that deal with that, or manually have them reflect on both applications.
Lastly, When creating the item that may have line items, do note that usually the creation of such object requires the first line item. So when we add line items to that object, we will have to make sure that the first line item will not be added again.
To fully understand this recipe, you will need to have the grasp of the following :
- Concept of List
- How to use Repeat Action
- How to map fields correctly
- How to use Search actions.
Let's get started!
When adding line items, the first would be to get all line items from an object. You can use the Search object action from Salesforce, or they should be accessible as a list in the object, such as order items in an Order in Shopify.
The screenshot above shows a list of items that you are able to loop through using the repeat action. Note that all other fields are not clickable as they are not a list. To access each item in that list and use their data fields, we will need to use the repeat action to access them.
Next, Using this list, we create a repeat action to loop through the list that you identified.
Repeat Action acts similarly to a Conditional action in the case of indentation. Any steps that are indented below a repeat action will be performed for each object in that list. For example, if your "Search Opportunity Products" output returns 10 objects in that list, for each of the 10 objects, the indented steps below will be performed.
This characteristics is extremely useful when you would like to move objects with line items between applications. For example, you can move you opportunity products from Salesforce into QuickBooks or Bill.com as invoice with line items. All you have to do is add in a add line item step to do so. Take note that in order to add line items to an object, a "Add Line Item to X" action must be available.
When you have a Repeat Action created, on your App Data on the right side of your recipe, you will see the Foreach Step output. This is the data fields for the single object in the list that the recipe is currently looping on. Therefore, when populating indented steps, make sure to use these fields of the list to get the right fields for each record.
For example, I have a Repeat action that says, do the steps below for each Opportunity Product that my Search action returned.
Then on my next step, when I fill in the fields for the indented step (Add line item to invoice in Bill.com) , I use the quantity data field coming from the Foreach loop.
Very easily, you will be able to add line items to your invoice by using the repeat action for the steps below:
Now do take note that there are some create actions that requires the first line item to be created with it. This is due to the nature of the application's API. Examples of such actions are Bill.com's Create Invoice action, QuickBooks' create Invoice as well as its Create Sales receipt action.
In Bill.com's Create invoice action, there is a Line Item fields that are needed to be filled in.
In QuickBooks' Create Invoice action, the When Choosing Sales Item Line Detail as the option, you will need to have the first line item as an actual item from QuickBooks with its details.
scrolling all the way to the bottom and click show more shows that the fields for the item detail.
In this case, with the Repeat action that we have, we would be creating duplicates of the first line item. We will be putting in the first line item when we create the invoice, and putting the first line item the second time when we add line item to it in our Repeat Action indented steps. This is not ideal, and there is a solution to it.
Note that ForEach actions is looping through a list of objects. Repeat actions have two special orange data pills call Index and Size. INDEX refers to the current object that the recipe is acting on. That means when we use the data pills from the ForEach step output, those fields value will be of the object of the index. For example, An INDEX of 0 means that the data pills for the ForEach step output is referring to the first object of list. SIZE refers to the size of the list that was picked up. For example, if the opportunity has 4 items in it, the Opportunity Product's SIZE would be 4.
Knowing that we can identify which Opportunity Product is the recipe on, we can then add a Conditional Action that says IF the INDEX of the ForEach action is not equals to 0, then do the following indented steps. This can be translated as DO NOT perform any indented steps if it is the first item in the list.
And there you have it, a very simple, five steps procedure that loops through a list of objects in an application, creates an record in another application and add line items to it.
Hope this helps. Let us know if you have any questions or feedback via live chat, and we'll be more than happy to help you out.