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


3 comments:

  1. This article was written by a real thinking writer without a doubt. I agree many of the with the solid points made by the writer. I’ll be back day in and day for further new updates. home-improvement-deductions-for-taxes-in-2020

    ReplyDelete
  2. Thank you for sharing the information. You can use this service to manage your business visit here for more details about dynamics 365 f&o.

    ReplyDelete
  3. Great article! microsoft dynamics 365 for finance and operations is undoubtedly an essential tool for businesses in the UAE. The pricing details are crucial for organizations looking to make an informed decision. As a Microsoft partner in the UAE, we have helped numerous businesses implement this powerful solution, and we can vouch for its effectiveness in streamlining financial processes, improving decision-making, and enhancing overall efficiency.

    ReplyDelete

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