Adding actions on OData entities


Actions let you inject behaviors into the data model. To add actions, add a method to the updatable view, and decorate that method with specific attributes.

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.

[SysODataActionAttribute(‘invoceSalesOrder’ , false)]
Public static void PostSalesOrderInvoice(SalesId _salesId)
{
    SalesTable salesTable = SalesTable:find(_salesId);
    SalesFormletter  salesFromletter = Salesformletter::construct(DocumentStatus:Invoice);
    salesFromletter.update(salesTable, systemDateGet(), SalesUpdate::All, AccountOrder::None, false, false);
}


This method will invoice the sales order id that has been passed as the argument.

[D365FO URL]/data/[data entity]/Microsoft.Dynamics.DataEntities. PostSalesOrderInvoice

For passing the parameter for the method, we can use the body section (Json)

{
            “_salesId”:”SO7646476”
}

with this way we can create and expose the custom methods as Odata actions.




Comments

Popular Posts