Power Automate & MSDyn365FO: Deep dive (III)

Power Automate & MSDyn365FO: Deep dive (III)

In this third and final post about Power Automate and its connector for Microsoft Dynamics 365 Finance and Operations apps, we are going to talk about the different write operations that exist in it. These operations are the following:

Before starting with them, we must bear in mind that these operations will be available only for those entities that have the Is Read Only property with value No, that is, entities that allow data to be written.

Visual Studio properties - Is Read Only = No
Visual Studio properties – Is Read Only = No

In fact, Power automate itself warns us, as we can see in the following screenshot:

Insert/Update/Delete not allowed for entities with ReadOnly = Yes
Insert/Update/Delete not allowed for entities with ReadOnly = Yes

Create record

We will use the Create record action, obviously, when we need to create new data within MSDyn365FO.

Power Automate - Create record
Power Automate – Create record

The first thing we need to indicate is the Instance on which we are going to work, and the entity on which we want to create new data. Once these two parameters have been selected, we will see how the necessary fields appear to be able to create the new record.

Power Automate - Create record
Power Automate – Create record

Continuing with the Customer group entity, we will indicate the minimum data necessary to be able to create the record, which are the customer group code and the company code. If we click on the link Show advanced options, the rest of the fields that are available within the entity will appear to complete the information. Once the flow is executed, we can see how the record has been created in the system.

Create record executed
Create record executed
Dynamics 365 F&O - Customer groups
Dynamics 365 F&O – Customer groups

Now, if we consult the IIS log of our instance, we can verify that Power Automate is making a POST http call over Dynamics 365, sending the data that we have completed in the flow in the body of the call.

Update a record

We can use the following action when we need to update a record within Dynamics 365 Finance and Operations apps.

Power Automate - Update a record
Power Automate – Update a record

If you look closely, this operation is very similar to the action we saw in the previous article with which we could Get a record. We must indicate the instance and entity on which we want to act, and we also have to enter the object Id that uniquely identifies the record we want to update. As we saw earlier, this is generally the company code, followed by the primary key of the entity.

Power Automate - Update a record
Power Automate – Update a record

Once these values are indicated, it also forces us to put the mandatory values, such as the Customer group (although it does not use that value to update), and if we are going to see the advanced options, the rest of the fields available in the entity will appear for you to update its value.

Once the action is executed, we can see how 2 operations appear in the IIS log:

These operations are, first a PATCH call, which it executes to update the record in question, followed by a GET operation that Power Automate performs to obtain the updated data of the record with which we are working, and thus be able to use them as Output of the action, and have these values in the next steps of our workflow.

Caution!: In the second GET operation, the system does not use the Object Id to obtain the data, but rather, it is using the CustomerGroupId, so if in the CustomerGroupId we put a different value to the Object Id, although we will correctly update the record that we indicate in it, the data that we will obtain in the output will be different. As you can see in the following image, the system would launch a PATCH against a record, and a GET on a different one. A little “crazy”, right?

Strange behaviour updating a record
Strange behaviour updating a record

In this action, just as it happened with the Get a record action, we must take special care with the order of the parameters within the Object Id, and we also have the limitation of the company assigned within MSDyn365FO, so if we try to update a record from a different company, we will find a 404 error as it will not find the resource to update.

Power Automate - Error 404
Power Automate – Error 404

Delete record

And we arrive to the last of Power Automate’s actions on MSDyn365FO: Delete record. As its name indicates, what we achieve with this action is to delete a record within the entity indicated in the input parameters.

Power Automate - Delete record
Power Automate – Delete record

To identify the record that we want to delete, we will follow the same mechanism as the one indicated in the actions of Get record and Update a record, that is, we will indicate the Dynamics 365 instance, the entity on which we want to act, and in the Object Id , we put the company followed by the primary key of the entity.

As we have seen a while ago, we must be strict with the arrangement of the elements that make up the Object Id, and again, we have the limitation created by not being able to use the cross-company parameter within this type of actions, so if we try to delete a record from a company other than the one assigned to us, we will find an error that is already known to everyone.

Power Automate - Error 404 deleting a record in other company
Power Automate – Error 404 deleting a record in other company

Finally, we are going to check the IIS log again to review the HTTP operation that Power Automate performs on our Dyn365 F&O instance.

This operation is a DELETE on the entity that we have indicated, taking the values that we have put in the Object Id to identify the record in question.

And here ends this series of posts about the Power Automate connector for Microsoft Dynamics 365 Finance and Operations. As you have seen, we can perform practically any type of operation with it, although it is true that we have a series of limitations and problems that can make it difficult for us to design a solution using this tool.

I hope you liked them and you found them useful. As always, I am open to any type of comment, doubt or criticism, and it only remains to wish you happy holidays and a happy new year

See you in 2021!! ✨

2 comments / Add your comment below

  1. Thanks. Can you write(and read) binary data? For example, attach image or file to a record?

    1. Hi Denis, thanks for commenting :).

      Yes, indeed I have a power app to attach images to released products through Power automate. I expect to create a post with the details soon.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Uso de cookies

Este sitio web utiliza cookies para que usted tenga la mejor experiencia de usuario. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información. ACEPTAR

Aviso de cookies