Monday, August 10, 2020

All about Azure Service Bus -- Azure Logic Apps -- Dynamics 365 F&O.

Hi DAX people.

Hope everyone is doing well out there..!!

Recently I started looking into Logic Apps integration with D365 F&O and faced few issues while achieving the goal. 

Hereby mentioning the same on what was the requirement and how I was able to overcome the issues.

 

Requirement: We need to update an entity(eg : SalesOrderHeaderV2Entity) available in D365 F&O using Logicapps and Service Bus Messaging Queue.

So the flow here is, from AX2012(send a message to) à Service bus queue(sends a message to)à Logic apps(uses D365 connector to update a record ) à D365 F&O(record will be updated).


Prerequisites :

  • D365 F&O and logic app application should be available on the same Tenant and subscription where the VM is deployed.
  • User must have permissions to create/ update the record in D365 F&O.
  • If the authentication method provided at Logic apps is Active directory OAuth, then in D365 F&O à under Active directory applications form, user must be registered with the same client Id which was provided at Logicapps.
  • Both Logic apps and The service bus must be integrated with the same Queue and subscription name.

Issues faced at logic Apps workflow designer while executing the flow :


There are few basic connectors already available In logic apps that can be used to perform CRUD operations.

You can find the available connectors here

https://docs.microsoft.com/en-us/connectors/dynamicsax/

  1. Authentication failed: This issue happens, when the user doesn’t have permissions to perform CRUD operations in D365 F&O.                          

Issue:

{
"status": 401,
"message": "{\r\n "Message": "Authentication failed.",\r\n "StackTrace": null,\r\n "ExceptionType": "System.InvalidOperationException"\r\n}\r\nclientRequestId: bcc52356-17ba-429c-9307-815a5aaa931c",
"source": "<<URL>>.ax.dynamics.com",
"errors": []
}

       Resolution:

  • Make sure that, the user has admin rights to perform the operation.
  • Check whether the record is available in D365 F&O à active directory applications (same client Id to be registered for both logic apps & D365)
  • Logic app in the Azure portal should be created with the same admin user.
  • Under the same Subscription and tenant id, both(logic app & D365 VM) should be available.
      ************************************************************

  1. ObjectID for Update Record operation through the logic app:  ObjectId is mandatory while using D365 F&O  “Update a record” connector.

When incorrect ObjectId is passed, will get the below issue. We have taken the data entity - > SalesOrderHeaderV2Entity  as an example below.

           Issue:   

           { "status": 400,

"message": "Only 1 of 2 keys provided for lookup, provide keys for dataAreaId,SalesOrderNumber for SalesOrderHeaderV2.\r\nclientRequestId: 44ede2ab-85b5-4853-832e-6218f77c2c53",

"source": ""<<URL>>.azurewebsites.net"

}

Resolution:

ObjectId is the combination of Legal entity( to which we need to search and update record) + Entity key (defined at SalesOrderHeaderV2Entity level).

Note: If there are multiple fields defined in Entitykey, then all the fields value to be specified in sequence order along with DataAreaId. 

************************************************************

  1. No resources were found when selecting for update:  When trying to execute logic app designer, it is unable to find the data in the provided D365 F&O instance.

 Issue :

{

  "status": 400,

  "message": "An error has occurred.  No resources were found when selecting for update.\r\nclientRequestId: c1c6e39f-897d-4ef0-a2ff-5046a23b23b3",

  "error": {

    "message": "An error has occurred.  No resources were found when selecting for update."

  },

  "source": "<URL>.cloudax.dynamics.com",

  "errors": []

}

 Resolution:  After providing all the valid inputs still, the values are not being fetched.

Found out that, Odata data entities look for the data in default user company (Default company can be configured for a user in User optionsà preferences in D365 F&O).

After providing the setup, it was able to select the record and update it without any issues.


************************************************************

4. Sales entity update in case of Retail POS: After providing all the valid inputs for a record update, we came across an error “The sales order header entity does not support updates of sales orders which are associated with a retail channel”

             Issue :

             {

  "status": 400,

  "message": "An error has occurred.  Write validation failed for table row of type 'SalesOrderHeaderV2Entity'. Infolog: Warning: The sales order header entity does not support updates of sales orders which are associated with a retail channel..\r\nclientRequestId: 485f5dc5-feb2-442f-abe5-b1ccde5f540e",

  "error": {

    "message": "An error has occurred.  Write validation failed for table row of type 'SalesOrderHeaderV2Entity'. Infolog: Warning: The sales order header entity does not support updates of sales orders which are associated with a retail channel.."

  },

  "source": "d365-dev-04f1d90146db8afd7edevaos.cloudax.dynamics.com",

  "errors": []

}

Resolution :  

  • Strictly to be checked with Business - Either override the standard validation written on code (Salesheaderentityv2àvalidateWrite()) by using Chain of command  and use “Update a record” connector(OR)
  • Duplicate the entire salesheaderentityV2 and create an Odata action method to Post using HTTP Patch request.

 Note: We found out that there is a limitation for Odata action methods(SysODataActionAttribute). At the moment, it will work only for custom entities.

Even if you create an extension for standard data entity(eg: salesheaderentityV2) and try to create the Odata action method, then that method will not be exposed to external applications(like logic apps, powerapps).

More information related to Odata action methods can be found here àhttps://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/odata#adding-actions-on-odata-entities

************************************************************

 5. Fetching the message(reading the values) from Service Bus queue to Logic apps :

 Issue:  As part of testing, we initially provided constant values on the logic app workflow designer and the data is getting updated. 

But when we tried to fetch message from service bus, values are not being read by Logic apps.

    Resolution :  

  • Ensure that the message which is being sent to Service bus is in JSON format, so that we can avoid the conversion logic in Logic apps.

Providing sample JSON format below

{

  "CustomerAccount": "000001",

   "SalesOrderNumber": "000001",

  "legalEntityId": "DAT"

}

  • In logic apps, the message which was read from the Service bus will be in the “Base64” format. We need to explicitly convert the Base64 to a logic apps understandable language. Then only messages can be read and processed.  For that, we have expressions available in logic apps designer to convert it to a string.
  • In the example provided above, we used base64ToString()

More details related to conversion functions and when to use can be found here: https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#conversion-functions

  

Other resources related to this topic:

                             In order to avoid dependency on the tool, Microsoft already incorporated this in Azure portal and it is in the preview phase. ( reference: https://azure.microsoft.com/en-in/updates/sesrvice-bus-explorer/)

 

 

Hope the above information helps when you start working on topics related to - Azure Logic Apps, Azure Service Bus, and D365 F&O.


Important Note : 

Moreover, if you want the service bus messages to be read and processed automatically, we can use the Trigger: When a message is received in a Topic Subscription(auto - complete).

The only thing to make sure is that Service bus subscription to be created without enabling sessions


Happy daxing.. !!







No comments:

Post a Comment