Sunday 3 April 2022

OData Action method in D365FO(FSCM) and test it using Postman tool

Using Data entity OData action method, we can now expose any custom business logic from D365, without having to create any custom service. And we can create and expose the methods for integrations processes. 

Here we are creating OData Action to validate the sales line price and putting sales orders on hold based on the validation logic from EDI(3rd party).

Step 1:  Create a custom Data entity in D365 Fno and create the OData Action method on the method node of Data entity



Here we have created a static method and decorated it with an attribute [SysOdataActionAttribute].
SysOdataActionAttribute class is used to expose the method as Action.
First, the argument is the Action name and 2nd is Boolean. If Boolean parm is true it means Action is available to use. 
Now we have created the Odata Action method and 3rd party will execute Action “priceValidateEDI” from  API. 



Step 2: Now we can call this Odata action by the below URL from the postman tool.

[D365FO url]/data/DataEntity name /Microsoft.Dynamics.DataEntities.ActionName

Step 3: How to set up postman tool : >

First, go to https://portal.azure.com and click on the "Azure Active Directory"



 Then click on "App registrations" and +New registration
1: Give App registration name 
2: select Any Azure AD Directory-Multitenant
3: select URI as Web and set D365 Fno URL and click Register.

Application created successfully. Now click on App permissions 


Click Add permission and select Microsoft Dynamics ERP


Then select "Delegated permissions" and "Application permissions" and give full permissions and then click Add permissions 






Then you can see the below screen and then "Grant Admin consent for ABC" and then you will see the green status, which means permissions Granted.  


Step 4: After that Create "Client Secret": Click new client secret then give Description and Expires, click Add.







Now click on Overview and copy the client and Tenant

 


Step 5: All the keys will be used in postman setups so copy from the above step4 and keep it like Client, Tenant, and Secret value.

Four Keys
grant_type   = client_credentials
client_id = {clientId}
client_secret = {client Secret}
resource = {d365 instance url}


Client : 
Tenant : 
Secret Value : 


Then Go to the D365 FO > System Administration > Azure Active Directory applications
Create a new record and give clientId and userid. 




Now we are all set to ready to test API in postman, 

Step 6: First, we need to create a request to generate the Access Token, then we will be able to access the D365FO API.

Decorate the URL(1) above to get the access Token, set the Tenant which already we have copied in steps 4 & 5, https://login.microsoftonline.com/Tenant/oauth2/token
and then click Body (2) and select Form-Data then you need to add Four Keys to generate the Token (3).



Step 7: Click send So here we can see the Access Token, copy the access token this will be used for Authorization.


Step 8: Now click new request and use the below URL for OData action method API 

[D365FO URL]/data/[Your data entity]/Microsoft.Dynamics.DataEntities.['Method name']

Sample URL: https://usnconeboxax1aos.cloud.onebox.dynamics.com/data/PriceValidationSOes/Microsoft.Dynamics.DataEntities.priceValidateEDI

Click the Authorization tab, then select Bearer Token and give access token which is copied from the above step 7.



Step 9: Click Body and we have 2 parameters in the OData action method so we are giving parameters as salesId and companyId as a parameter in JSON.
On clicking the 'send button for POST request, the called method will be executed.




Step 10: We can go back to D365FO to check if this succeed. Below is the screenshot, where the mentioned sales order has been on-hold.




Many Thanks:-) 























 










































































Import General journal from excel in D365 F&O

 Hi Guys, Import General journal from excel in D365 F&O Code:  using System.IO; using OfficeOpenXml; using OfficeOpenXml.ExcelPackage; u...