D365 Field Service: Add child assets to an RMA
A few weeks ago I was talking to someone about Dynamics 365 Field Service and they asked me about a couple of requirements which were not standard functionality in Dynamics 365 Field Service. He wanted to know if it was possible to build logic around assets that are brought to a warehouse for repair. The scenario was that when a part is picked up from a customer to send to a warehouse for repair, a RMA record needs to be created in the system. If you are familiar with Dynamics 365 Field Service you’ll know that’s not the hard part, we can do this in Dynamics 365 Field Service today, out of the box. The functionality that he was looking for was that when a part (in this case a customer asset) is being picked up for repair, the system should check to see if the part has child or sub-assets attached. If this is the case, then the system should automatically add these child or sub-parts to the RMA. Not a very difficult scenario, but still something that I would need to build out. In this article I’ll explain how I built this logic!
Since I need to query Dataverse to see if the customer asset has related child or sub-assets, I choose to use Power Automate for this. I want to run this Power Automate flow automatically each time an asset is manually added to an RMA, which means that the trigger for this cloud flow will be looking at the RMA products table. There are 2 things to note here, the first one being that I don’t want this flow to run if the customer asset lookup field on the RMA Product record is blank. The other thing that you need to keep in mind is that you might not want to run this flow on the RMA product records that are being created by this flow? In my case I actually want to run my flow on those records, just in case the child assets have additional child assets related to them. So for example if there is an asset that is a radio, which has a child asset which is a microphone and the microphone has another child asset, let’s say a microphone switch, then I want those assets to be included in the RMA!
Building the Power Automate flow
Now that we know what we need to do we can start building our Power Automate flow! Go to make.powerautomate.com and open the solution you want to create the flow in. On the top of the screen on the command bar, select the arrow next to ‘+New’ and select ‘Automation’, then ‘Cloud flow’ and then ‘Automated’. This will load the ‘Build an automated cloud flow’ screen, which I usually skip through as I prefer the full screen when staring to build these Power Automate flows. In order to skip this smaller screen you can click ‘Skip’ on the bottom of the window. In the full Power Automate screen that loads I would recommend naming your flow. You can do this by typing a name in the top left side of the screen that reads ‘Untitled’. I called my Power Automate flow ‘Add child assets to RMA’. Our first step in building this flow is to find the right trigger. I am looking for the Dataverse trigger called ‘When a row is added, modified or deleted’. Once the trigger has been selected I change the ‘change type’ to ‘Added’ and select the ‘table name’ to RMA Products.
As I mentioned above, I don’t want this flow to run if the customer asset field is blank, so you’ll notice that I am filtering the rows with the following statement: (_msdyn_customerasset_value ne null)
Click ‘+New Step’ and select the Dataverse step ‘Get a row by ID’. This is where we’re going to collect the unique identifier of the customer asset that has been populated in the RMA Product. In this case we will be looking for customer assets, so be sure to set this as the table name in this step. For the row ID we’ll use the dynamic value field ‘Customer Asset (Value)’ from the trigger step as shown below.
In the next step I want to list all the child assets related to the customer asset that is selected on the RMA product that triggered this flow. In order to do this we will click ‘+New Step’ again below the previous step we created and we will be looking for the ‘List rows’ step also for Dataverse. Since we’re looking for child assets, we will need to select the customer asset table as the table name. Since we don’t want to return all customer assets in the system, but only the child assets of the asset selected on the RMA product I’ll put a filter in that will look like this: (_msdyn_parentasset_value eq ENTER THE DYNAMIC VALUE OF THE CUSTOMER ASSET FROM THE ‘GET A ROW BY ID’ STEP HERE)
As you can see in the image below we would get the dynamic value of the customer asset’s unique id from the ‘get a row by id’ step we created previously. Below is the image of what the step looks like.
In the next step I’ll need to get details from the product of each individual child asset . We’ll need this later when we are creating the RMA products for the child customer assets. In order to do this I’ll create another ‘Get a row by ID’ step. The table name is ‘Products’ and for the row ID I’ll use the dynamic value ‘Product(Value)’ from the first ‘List rows’ step in the flow. You’ll notice as soon as you populate the row ID field in the step, Power Automate automatically puts the step in an ‘Apply to each’ box, because we are getting the row ID for multiple records (We’re getting the products for each of the child assets).
For the next step it’s important to understand that we want the Power Automate flow to do different things depending on what the RMA product’s processing action is.
NOTE: Both the RMA and RMA Product tables have a processing action field. For this logic I’ll be looking at the RMA Product’s processing action. I am only focusing on the action when the processing action is a return to warehouse, but wanted to show you that other actions can be configured based on this field.
Because the processing action field is an option set, I will use the switch step to configure the next step. Keep in mind we want to add this step inside the ‘Apply to each’ box that was added by Power Automate in the previous step. Inside the ‘Appy to each’ box, click on ‘+Add an action’ and search for the switch step. In the ‘On’ field in the switch step enter the dynamic content ‘Processing Action’ from the trigger step. Below the first case section, enter 690970001 in the ‘Equals’ field. This represents the Return to Warehouse option from the option set field. If you want to add logic when a different value is selected, you can click on the ‘+’ button to add these. I would suggest renaming ‘Case’ to these values (I.E Return to Warehouse, RTV) for clarification.
Below the case with the value of 690970001 I am going to create a final step where we’re adding the child customer assets to the RMA as RMA products. Click on ‘Add an action’ in the case box, then select ‘Add a new row’. The table name is RMA Products. Select ‘Pending’ as the item status. Then select the Price List (Value) in the Pricelist field. If you’re using a dynamic value, don’t forget to enter /pricelevels and an opening and closing bracket around the dynamic pricelist value. In my flow this value comes from the ‘Get a row by ID 2’ step, but you could also grab the price list related to the account if that works better for you. For ‘processing action’ I am using a dynamic value from the trigger step, but since this ‘Add a new row’ action will only happen for records that have their processing action set to ‘Return to warehouse'(configured in the switch), it’s safe to manually select that here as well.
The product field is where we will enter the related product for the RMA Product, which is coming from the ‘List rows’ step. Make sure you type /products with the opening and closing brackets around the dynamic product value. I entered 1 for quantity as in my scenario there will always be 1 customer asset per RMA Product. Since I am adding these RMA Products to the same RMA, I am populating the RMA(RMAs) field in the step with the RMA’s unique id from the trigger. Don’t forget to type /msdyn_rmas with the opening and closing brackets around the dynamic RMA value. For the ‘Taxable’ field I grabbed the (dynamic) value from the ‘Get a row by ID 2’ step, which is where we’re getting the products related to the child customer assets. For the ‘Total Amount’ I am just grabbing the list price from the related product which comes from the ‘Get a row by ID 2’ step, since my quantity is always 1 in this scenario.
The value for the ‘Taxable’ field in the flow is also coming from the related product. I am populating the Unit(units) field also from the ‘Get a row by ID 2’ step, which, as I mentioned before, is the related product. The dynamic value is called ‘Default Unit(Value)’.
For the ‘Unit Amount’ I could add a step to search for price list items that are related to the pricelist, but in this case I am just grabbing the list price from the related product which also comes from the ‘Get a row by ID 2’ step. My Power Automate flow wouldn’t work without the currency, so I populated that as well, this is again coming from the ‘Get a row by ID 2’ step. The customer asset field needs to be populated with the customer assets from the ‘List rows’ step, where we query for the child assets. I also need to populate the return to warehouse, which comes from the related RMA. This value is coming from the trigger step as shown in the image above. One last thing I want to mention, I changed the ‘Line order’ field on the RMA Product table from ‘business required’ to ‘business recommended’ so that I don’t have to enter anything in that field in my flow. If you want to take a look at this Power Automate flow, you can download the unmanaged solution here and import it into your sandbox environment. Keep in mind you need to have Dynamics 365 Field Service installed in order to import the solution. Also please note that I haven’t done a lot of testing on this flow, which I recommend you do prior to implementing this!
I hope you found this article informative! Be sure to check in again next week for a new article or subscribe here to never miss another post!
Comments are Closed