Create Custom Services in D365 F&O and Test using Postman Part-1
Greetings,
I am pleased to present to you my latest blog post on creating a custom web service in Dynamics 365 Finance & Operations and accessing it through Postman. This tutorial will be divided into two parts, in which we will discuss the steps required to create and expose web services to external systems using Dynamics 365 Finance & Operations.
In the first part, we will delve into the Dynamics 365 Finance & Operations platform and discuss the steps required to create web services. As an example scenario, we will consider a situation where a third-party system needs to retrieve information about a specific vendor, such as their name, vendor group, and balance, from D365 for a given legal entity.
In the second part, we will introduce Postman and its usage in testing web services.
This approach serves as a starting point for integrating a third-party system with Dynamics 365 Finance & Operations.
Kindly Note: This is one of the approaches to achieve the above requirement.
So let's start...
Step 1: Create a new contract class to take the
parameter from the third party.
class VendorIDContract
{
VendAccount vendorId;
DataAreaId legalEntity;
[DataMemberAttribute('vendorId')]
public VendAccount parmVendorId(VendAccount _vendorId = vendorId)
{
vendorId = _vendorId;
return vendorId;
}
public VendAccount parmLegalEntity(DataAreaId _legalEntity = legalEntity)
{
legalEntity = _legalEntity;
return legalEntity;
}
}
Step 2: Create a new contract class that will return the Vendor data.
class VendorMasterContract
{
VendAccount vendorId;
Name vendorName;
VendGroupId vendorGroup;
Amount vendorBalance;
str StatusMessage;
public VendAccount parmVendorId(VendAccount _vendorId = vendorId)
{
vendorId = _vendorId;
return vendorId;
}
public Name parmVendorName(Name _vendorName = vendorName)
{
vendorName = _vendorName;
return vendorName;
}
public VendGroupId parmVendorGroup(VendGroupId _vendorGroup = vendorGroup)
{
vendorGroup = _vendorGroup;
return vendorGroup;
}
public Amount parmVendorBalance(Amount _vendorBalance = vendorBalance)
{
vendorBalance = _vendorBalance;
return vendorBalance;
}
public str parmStatusMessage(str _StatusMessage = StatusMessage)
{
StatusMessage = _StatusMessage;
return StatusMessage;
}
}
Step 3: Create a Service Operation class and add the business logic.
{
[AifCollectionTypeAttribute('_keys', Types::Class, classStr(VendorIDContract))]
public VendorMasterContract getVendorBalance(List _keys)
{
VendorMasterContract vendorMaster;
VendorIDContract vendorId;
ListEnumerator listEnumerator = _keys.getEnumerator();
VendTable vendTable;
VendTrans vendTrans;
DataAreaId legalEntity;
listEnumerator.moveNext();
vendorId = listEnumerator.current();
legalEntity = vendorId.parmLegalEntity();
{
changecompany(legalEntity)
{
select vendTable where vendTable.AccountNum == vendorId.parmVendorId();
if(vendTable)
{
select sum(AmountMST) from vendTrans where vendTrans.AccountNum == vendTable.AccountNum;
vendorMaster.parmVendorName(vendTable.name());
vendorMaster.parmVendorGroup(vendTable.VendGroup);
vendorMaster.parmVendorBalance(vendTrans.AmountMST);
vendorMaster.parmStatusMessage("Vendor found");
}
else
{
vendorMaster.parmStatusMessage("Vendor not found");
}
}
}
else
{
vendorMaster.parmStatusMessage("Invalid Legal Entity");
}
return vendorMaster;
}
}
Right Click on the Project and click on the “Add” à “New
Item” under Services à
Service. Give a logical name in my case its “DemoVendorAPI”
Change the below properties of the Service and add your
method.

Step 5: Create a Service Group.
Right Click on the Project and click on the “Add” à “New
Item” under Services à
Service. Give a logical name in my case its “DemoVendorAPIGroup”

Set “Auto Deploy” as “Yes” and add the Service to the Service Group.
So your final projects should have the below objects. Build your project.Testing your Service on the Web browser
URL: https://{Your website name}/api/services/{Service-Group}/{Service}/{Method}
If you get below schema, then your service is good to
go.
Please Visit below link for Part 2
https://vikasaxaptandd365fno.blogspot.com/2022/12/create-cusotm-services-in-d365-f-and_21.html
Comments
Post a Comment