Custom service D365
1)
Create contract class
Example Code:
[Microsoft.Dynamics.BusinessPlatform.SharedTypes.InternalUseOnlyAttribute,
DataContractAttribute ('TANVehicleMasterDataContract')]
class TANVehicleMasterDataContract
{
SalesAgreementId salesAgreementId;
TANVehicleCategory vehicleCategory;
TANVehicleFuelType fuelType;
int vehicleID;
TANPlateNo plateNo;
TANModel model;
TAN_RFID_Gatex RFIDGatex;
TANOdometer_Gatex odometerGatex;
int total;
[DataMemberAttribute("TotalCount")]
public int parmTotalCount(int _total = total)
{
total = _total;
return total;
}
[DataMemberAttribute("SalesAgreementId")]
public SalesAgreementId parmsalesAgreementId(TANVehicleCategory _salesAgreementId =
salesAgreementId)
{
salesAgreementId = _salesAgreementId;
return salesAgreementId;
}
[DataMemberAttribute("VehicleCategory")]
public TANVehicleCategory parmVehicleCategory(SalesAgreementId _vehicleCategory =
vehicleCategory)
{
vehicleCategory = _vehicleCategory;
return vehicleCategory;
}
[DataMemberAttribute("FuelType")]
public TANVehicleFuelType parmFuelType(TANVehicleFuelType _FuelType = FuelType)
{
FuelType = _FuelType;
return FuelType;
}
[DataMemberAttribute("VehicleID")]
public int parmVehicleID(int _vehicleID =
vehicleID)
{
vehicleID = _vehicleID;
return vehicleID;
}
[DataMemberAttribute("PlateNo")]
public TANPlateNo parmPlateNo(TANPlateNo _PlateNo = PlateNo)
{
PlateNo = _PlateNo;
return PlateNo;
}
[DataMemberAttribute("Make")]
public TANMake parmMake(TANMake _make = make)
{
make = _make;
return make;
}
[DataMemberAttribute("Model")]
public TANModel parmModel(TANModel _model = model)
{
model = _model;
return model;
}
[DataMemberAttribute("RFIDGatex")]
public TAN_RFID_Gatex parmRFIDGatex(TAN_RFID_Gatex _RFIDGatex =
RFIDGatex)
{
RFIDGatex = _RFIDGatex;
return RFIDGatex;
}
[DataMemberAttribute("OdometerGatex")]
public TANOdometer_Gatex parmOdometerGatex(TANOdometer_Gatex _OdometerGatex =
OdometerGatex)
{
OdometerGatex = _OdometerGatex;
return OdometerGatex;
}
}
2)
Create service class
Example
code:
class TANSalesAgreementService
{
[AifCollectionTypeAttribute('return', Types::Class, classStr(TANVehicleMasterDataContract))]
public List getVehicleMaster(str FromDate,str ToDate)
{
TANVehicleMasterDataContract dataContract;
TANVehicleDetails vehicleMaster,vehicleMasterCount;
TANCustVehicleMaster TANCustVehicleMaster;
List
VehicleMasterDataContractList = new List(Types::Class);
utcDateTime
fromDateTime,toDateTime;
fromDateTime = str2datetime(FromDate, 213);
toDateTime = str2datetime(ToDate, 213);
int totalCount = 0;
while select vehicleMaster
{
if(
vehicleMaster.ModifiedDateTime >= fromDateTime &&
vehicleMaster.ModifiedDateTime <=
toDateTime )
{
TANCustVehicleMaster = TANCustVehicleMaster::findbyplateNo(vehicleMaster.PlateNo);
dataContract = new TANVehicleMasterDataContract();
dataContract.parmsalesAgreementId(vehicleMaster.SalesAgreementId);
dataContract.parmVehicleCategory(TANCustVehicleMaster.VehicleCategory);
dataContract.parmFuelType(TANCustVehicleMaster.TANVehicleFuelType);
dataContract.parmVehicleID(TANCustVehicleMaster.TANVehicleId);
dataContract.parmPlateNo(vehicleMaster.PlateNo);
dataContract.parmMake(TANCustVehicleMaster.Make);
dataContract.parmModel(TANCustVehicleMaster.Model);
dataContract.parmRFIDGatex(vehicleMaster.RFID_Gatex);
dataContract.parmOdometerGatex(TANCustVehicleMaster.Odometer_Gatex);
VehicleMasterDataContractList.addEnd(dataContract);
}
}
return
VehicleMasterDataContractList;
}
}
3)
Create Add new Service and associate your class
with newly created service
4) Class association with service.
5) Add method of your class in service operations node those you want to expose
6)
Add Service
group
7)
Set the service property Auto deploy= YES
8)
Associate your service with the service group.
9)
Perform Build & Sync and verify from
browser..
Service URL
https://usnconeboxax1aos.cloud.onebox.dynamics.com/api/services/[YourServiceGroupName]/[YourServiceName]/[YourMethodName]
Sample URL
https://usnconeboxax1aos.cloud.onebox.dynamics.com/api/services/TANSalesAgreementService/TankitSalesAgreement/getVehicleMaster
Comments
Post a Comment