Flow to create Order Products from Opportunity Products

Flow to create Order Products from Opportunity Products

I don’t know about you, but I figure out how to build a Flow, and then I have to do something similar and I have to figure it all out again. So I decided to document how to create one of my most useful Flows: Creating Order Products from Opportunity Products when an Order is created.

Overview:

 

Getting Started: First create the Flow

First you will select to create a record-triggered Flow

Trigger the Flow when a record is created and run the flow after it is saved

 

 

Choose the Object: Order

Condition Requirements: None

 

Now it’s time to build the Flow

1. The first Flow Element that you are going to add is a “Decision”

Does the Order have an Opportunity associated?

I’m going to use the record I started the Flow with: $Record and check to see if the Opportunity ID is Null. If that is false (so there is an ID),

then the Flow will continue

2. The second Flow Element is “Get Records”

Object = Opportunity Products

Conditions: Opportunity ID (of the Opportunity Products you are searching for) equals the Opportunity ID of the Order record that started the Flow

Store all records

 

3. The third Flow Element will be a decision to determine if the “Get Opportunity Products” returned any products:

 

 

Now we are going to have to loop through all of the Opportunity Products. Loops are where I can have some trouble. It took some time for me to understand. First you loop through the collection or records you found (all of the Opportunity Products), then we are going to grab the values from those fields and map them to a record variable we will create for the new Order Product records, once they are assigned to that variable, we have to assign those back to another, updated collection (I will name this one OrderProductsToInsert). The collection variable gets sent back to the loop, and then after the loop goes through each item in the collections it proceeds on its path. I’ll break it down step by step.

 

4. The fourth Flow Element you will add is a “Loop”

You will use the Collection variable that was created from your “Get Records” = Opportunity Products

({!Get_Opportunity_Product_Records})

You can leave the direction as first item to last item.

 

5. Now we have to create a variable so we have a place to store the values from the Opportunity Products in the Loop. We will call this variable newOrderProduct, since we are going to use the values stored in it to create our new Order Products

Under the Manager Tab, create a New Resource

 

 

Data Type = record

Object = Order product

6. The next Flow Element you will add to your Flow is an “Assignment”

Assign values to the newOrderProducts variable you just created. You will look up that variable’s values on the left in the Variable boxes

The operator will be “Equals” and you will get the value to set that newOrderProduct field from the Loop collection

Just look for the same field in the variable boxes as in the value boxes

For the Order ID you don’t have to use the values in the Loop. You can use the ID value of the original record that started the Flow: $Record

 

Here is how it will look for you to find the correct fields for the Value boxes:

 

 

7. Now it’s time to create a Variable

This variable will be a collection variable that will store all of the newOrderProduct records that were updated in the previous “Assignment” Flow Element.

You will create this by creating a new Resource on the Manager tab

 

 

Type: Variable

Name of the variable: OrderProductsToInsert

Data Type: Record

Allow multiple values (this makes it a collection and can store all of the records)

Object: Order Product

 

 

8. After you have created your collection variable to store the updated Order Product values, it’s time for another “Assignment” Flow Element

Assign newOrderProducts to OrderProductsToInsert collection

In the variable box you are selecting that collection variable that you just created (OrderProductsToInsert)

Operator = Add

(because you want to add the values stored in the newOrderProduct variables that we assigned in step 6)

Value = newOrderProduct

 

9. The next Flow Element will be an “Assignment”, but first we have to create a new resource

In order to create Order Products, the Order will need to be assigned a Price Book. We can get that Price Book from the Opportunity associated with the original Order record that started our Flow ($Record)

Operator is Equals

Value: Is going to be a resource formula variable that you need to create in the Manager

Start with the Order ($Record) get the Opportunity and then the Price Book ID from that Opportunity

 

 

You will use this formula as the Value in the “Assignment” to set the Order Price Book

The Variable will be the $Record Price Book ID

Operator is Equals

Value is this new formula resource you created (PricebookID2)

 

11. The next Flow Element we will drag onto the canvas is “Update Records”

Update Order Record

Use the IDs and all field values from a record or record collection

Record or Record Collection = {!Record.} That is the Order that started the Flow

We are updating it with the Price Book from the formula resource we just created

 

12. The final Flow Element that we need is “Create Records”

Create Order Products

How Many records to create: Multiple (because we want all of the Order Products created, one to match each Opportunity Product found on the Opportunity)

Record Collection: OrderProductsToInsert

This is telling it to go back to the record collection we created earlier to store all the Opportunity Product values that we want to use for the new Order Product records

The collection already has the values for the fields, so this Flow Element is taking those values and creating a new record for each item

 

 



Helping small businesses to increase profits by streamlining data management.