OData Action in D365FO and Using it in logic apps
Step 1: Create a OData action method in data entity as below and compile the code to see the method in logic app or postman.
With input parameter:
[SysODataActionAttribute("SalesOrderConfirm", false)] --If your method is Static then it should be false else True
public static void salesOrderConfirm(str _salesId, DataAreaId _company)
{
SalesTable salesTable;
SalesFormLetter salesFormLetter;
salesTable = SalesTable::find(_salesId);
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
salesFormLetter.update(salesTable, DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()), SalesUpdate::All);
}
With List as Response:
[SysODataActionAttribute("GetSalesOrders", False), SysODataCollectionAttribute("return", Types::Record, "SalesOrder")] public static List GetSalesOrders(str custAccount, DataAreaId company) { List returnList = new List(Types::Record); changecompany(company) { SalesTable SalesTable; while select SalesTable where SalesTable.CustAccount == custAccount { returnList.addend(SalesTable); } } return returnList; }
With input and ouput:
[SysODataActionAttribute("GetSalesStatus", False)]
public static str getStatus(str salesId, DataAreaId company)
{
str status;
changecompany (company)
{
status = enum2Str(SalesTable::find(salesId).SalesStatus);
}
return status;
}
With Instance method(Action atrribute to True):
[SysODataActionAttribute("GetLineCount", true)]
public int GetLineCount()
{
int lineCount;
changecompany (this.DataAreaID)
{
Salesline salesline;
select count(RecId) from salesline
where salesline.SalesId== this.SalesId;
lineCount = salesline.RecId;
}
return lineCount;
}
Step 2: Create a logic app to trigger the odata action method
1. Search HTTP and select When http request is received.
2. Prepare JSON format your input values in my case Sales id, DataareaId.
{
"SalesId":"",
"Company":""
}
3. Search fin & apps and select Execute action trigger.
- Specify Instance,
- Action(Your method Name. In this case SalesOrderConfirm)
- Set input parameters(SalesId, Company).
Logic App Flow:
Test the flow with LA and Postman:
Create POST request in Postman :
- For Non instance method output and URL
POST: https://D365URL/data/MyEntity/Microsoft.Dynamics.DataEntities.SalesOrderConfirm
- Instance method output and URL
Thanks for reading!!
No comments:
Post a Comment