Showing posts with label Testing Dynamics 365 Odata actions in postman. Show all posts
Showing posts with label Testing Dynamics 365 Odata actions in postman. Show all posts

Tuesday, June 12, 2018

Testing Odata actions for instance methods in Dynamics 365 for Finance and Operations

The details for testing an Odata action for a static method has been described in my previous post (http://vishwad365fo.blogspot.com/2018/05/testing-odata-actions-in-d365.html).

In this post, I would like to share the changes to be made to call an instance method.

If you have noticed the Odata action in the standard data entity 'ProjectEntity'

 [SysODataActionAttribute("GetProjectTypes", true),
     SysODataCollectionAttribute("return", Types::String)]
    public List GetProjectTypes()
    {
        DictEnum enumDict = new DictEnum(enumName2Id(enumstr("ProjType")));
        List enumLabels = new List(Types::String);
        int i ;
        str enumValue;

        for (i = 0; i < enumDict.values(); i++)
        {
            enumValue = enumDict.index2Label(i);
            if (enumValue != "")
            {
                enumLabels.addEnd(enumValue);
            }
        }
        return enumLabels;

    }

The second parameter, highlighted in 'Yellow' which is set to 'true', in the above code, signifies that it is an instance method.
So, if it is an static method, it has be set to 'false'.

So, we know how to call the static Odata actions, but will the same syntax work for instance methods?
No.
We have to make certain changes for that, since for the instance methods, we have to first select the data/record. As simple as selecting the table buffer first and then calling its instance methods.
In order to do that, we will have to pass 'primary key' for the entity and also the data area Id.

Syntax is as below:
https://<Base URL>/data/'dataentity name'('primary key', 'dataAreaId')/Microsoft.Dynamics.DataEntities.'Odata action method name'

For an Project entity, it would be:
https://<Base URL>/data/Projects(ProjectID='Proj-001', dataAreaId='USRT')/Microsoft.Dynamics.DataEntities.GetProjectTypes


Thursday, May 3, 2018

Testing Odata actions in Dynamics 365

With new Odata actions, we can now expose any custom business logic from D365, without having to create an custom service.
Apart from using the data entities for data integrations, we can also create and expose the methods too, as Odata actions.They can be used for the process integrations.

For example, using a SalesTable entity to create an Odata action to confirm or invoice the sales order.

Here is the simple example on testing the Odata actions in D365, using a tool called 'Postman'.

For the basic setup and for authentication the below url can be followed:


In this example, I have created a new static method for my custom entity.
The only new thing is, it has been decorated with [SysODataActionAttribute]



This method will invoice the sales order id that has been passed as the argument.
[Your organization's root URL]/data/[Your data entity]/Microsoft.Dynamics.DataEntities.['Method name']

For passing the parameter for the method, we can use the body section:


On clicking the 'Send' button for the POST request, the called method will be executed.

We can go back to D365FO to check if this succeed.
Below is the screenshot, where the mentioned sales order has been invoiced.



So, with this way we can create and expose the custom methods as Odata actions.
The example is for static method, but you can also try with the instance method for the data entity.



Quick & Easy way to create XSD from Dynamics 365 for finance and operations

If you are looking for an quick & easy way to create XSD (schema) from Dynamics 365 for finance and operations. Below is the way, ...