Power Automate and its connector for Microsoft Dynamics 365 Finance and Operations apps
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](https://i2.wp.com/jatomas.com/wp-content/uploads/2020/12/0-PropiedadReadOnly.png?resize=456%2C272&ssl=1)
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](https://i2.wp.com/jatomas.com/wp-content/uploads/2020/12/no-funciona-con-entidades-read-only-1.png?resize=394%2C195&ssl=1)
Create record
We will use the Create record action, obviously, when we need to create new data within MSDyn365FO.
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](https://i1.wp.com/jatomas.com/wp-content/uploads/2020/12/2-createRecord.png?resize=750%2C312&ssl=1)
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](https://i1.wp.com/jatomas.com/wp-content/uploads/2020/12/4-customerGroupCreated-USRT-1.png?resize=750%2C521&ssl=1)
![Dynamics 365 F&O - Customer groups](https://i2.wp.com/jatomas.com/wp-content/uploads/2020/12/3-customerGroupCreated.png?resize=362%2C248&ssl=1)
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.
1
|
2020-12-20 18:22:31 POST /data/CustomerGroups ja.tomas@axazure.com - 201
|
1
2
3
4
5
6
7
8
9
10
11
12
|
{
"dataAreaId": "usmf",
"CustomerGroupId": "JAT",
"ClearingPeriodPaymentTermName": "",
"CustomerAccountNumberSequence": "",
"DefaultDimensionDisplayValue": "",
"Description": "",
"IsSalesTaxIncludedInPrice": "No",
"WriteOffReason": "",
"PaymentTermId": "",
"TaxGroupId": ""
}
|
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](https://i0.wp.com/jatomas.com/wp-content/uploads/2020/12/1-updateRecord.png?resize=750%2C218&ssl=1)
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](https://i2.wp.com/jatomas.com/wp-content/uploads/2020/12/2-updateRecord.png?resize=750%2C356&ssl=1)
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:
1
2
|
2020-12-20 18:59:40 PATCH /data/CustomerGroups(dataAreaId='USMF',CustomerGroupId='10') ja.tomas@axazure.com - 204
2020-12-20 18:59:40 GET /data/CustomerGroups(dataAreaId='USMF',CustomerGroupId='10') ja.tomas@axazure.com - 200
|
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](https://i1.wp.com/jatomas.com/wp-content/uploads/2020/12/image-1.png?resize=537%2C40&ssl=1)
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](https://i1.wp.com/jatomas.com/wp-content/uploads/2020/12/3-errorCompany-1024x383.png?resize=780%2C292&ssl=1)
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](https://i1.wp.com/jatomas.com/wp-content/uploads/2020/12/2-deleteRecord.png?resize=750%2C218&ssl=1)
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](https://i2.wp.com/jatomas.com/wp-content/uploads/2020/12/3-error-deleteCrossCompany.png?resize=780%2C332&ssl=1)
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.
1
|
2020-12-20 18:41:08 DELETE /data/CustomerGroups(dataAreaId='USMF',CustomerGroupId='JAT') ja.tomas@axazure.com - 204
|
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.
posted on 2022-01-30 13:24 lingdanglfw 阅读(95) 评论(0) 编辑 收藏 举报