How to Create a Custom Service in D365fo (Using Data Contract)
Create custom service in D365fo:
- Create the Request Class.
- Create the Response Class.
- Create the Service Class.
- Create the Service Object.
- Create the Service Group.
Request Class
[DataContractAttribute]
class TBS_VendRequest
{
private DataAreaId dataAreaId;
private VendAccount accountNum;
[DataMember("DataAreaId")]
public DataAreaId parmDataAreaId(DataAreaId _dataAreaId = dataAreaId)
{
if (!prmIsDefault(_dataAreaId))
{
dataAreaId = _dataAreaId;
}
return dataAreaId;
}
[DataMember("AccountNum")]
public VendAccount parmAccountNum(VendAccount _accountNum = accountNum)
{
if (!prmIsDefault(_accountNum))
{
accountNum = _accountNum;
}
return accountNum;
}
}
Response Class
[DataContractAttribute]
class TBS_VendResponse
{
private boolean result;
private str error;
private DataAreaId dataAreaId;
private VendAccount accountNum;
[DataMember("Error")]
public str parmError(str _error = error)
{
if (!prmIsDefault(_error))
{
error = _error;
}
return error;
}
[DataMember("Result")]
public Boolean parmResult(Boolean _result = result)
{
if (!prmIsDefault(_result))
{
result = _result;
}
return result;
}
[DataMember("DataAreaId")]
public DataAreaId parmDataAreaId(DataAreaId _dataAreaId = dataAreaId)
{
if (!prmIsDefault(_dataAreaId))
{
dataAreaId = _dataAreaId;
}
return dataAreaId;
}
[DataMember("AccountNum")]
public VendAccount parmAccountNum(VendAccount _accountNum = accountNum)
{
if (!prmIsDefault(_accountNum))
{
accountNum = _accountNum;
}
return accountNum;
}
}
Service Class
public class TBS_VendService
{
[AifCollectionTypeAttribute('return', Types::Class, classStr(TBS_VendResponse))]
public List read(TBS_VendRequest _request)
{
TBS_VendResponse response;
VendTable vendTable;
List ret = new List(Types::Class);
try
{
while select crosscompany vendTable
where (!_request.parmDataAreaId() || (vendTable.DataAreaId == _request.parmDataAreaId()))
&& (!_request.parmAccountNum() || (vendTable.AccountNum == _request.parmAccountNum()))
{
response = new TBS_VendResponse();
response.parmResult(true);
response.parmDataAreaId(vendTable.DataAreaId);
response.parmAccountNum(vendTable.AccountNum);
ret.addEnd(response);
}
}
catch (Exception::CLRError)
{
System.Exception interopException = CLRInterop::getLastException();
response = new TBS_VendResponse();
response.parmResult(false);
response.parmError(interopException.ToString());
ret.addEnd(response);
}
return ret;
}
}
Service Object
- Add new Service.
- Set Name "TBS_VendorService".
- Set External Name "TBS_VendorService".
- Set the "Class" property with the name of the Service Class "TBS_VendService".
- Add new service operation:
- Set the "Method" property with method name in service class "create".
- Set the "Name" property.
Service Group
- Add new service group and set name "TBS_VendServiceGroup".
- Add new service:
- Set the "Service" property with service name "TBS_VendService".
- Set the "Name" property.
Comments
Post a Comment