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


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, ...