x++ code to create custom service to cancel the work header cancellation
Description: Helps with Cancelling the work order header based on the WorkId, dataAreaId.
URL: {url}}/api/services/BASMSServices/BASMSAdvanceWarehouseService/ getWorkHeaderCancellation
Request class: Below mentioned are the parameters, user needs to pass as a request contract to the system.
WorkId: work Id for the given work.
DataAreaId: company from which sales orders need to be retrieved
Request Contract Class:
[DataContractAttribute("BASMSWorkHeaderCancellationRequestContract")]
class BASMSWorkHeaderCancellationRequestContract
{
str workId;
str dataAreaId;
[DataMemberAttribute("WorkId")]
public str parmWHSWorkId(str _workId = workId)
{
workId = _workId;
return workId;
}
[DataMemberAttribute("dataAreaId")]
public str parmdataAreaId(str _dataAreaId = dataAreaId)
{
dataAreaId = _dataAreaId;
return dataAreaId;
}
}
Response class:
[DataContractAttribute("BASMSWorkHeaderCancellationResponseContract")]
class BASMSWorkHeaderCancellationResponseContract
{
str workStatus;
List errorList;
[DataMember('WorkStatus')]
public str parmWorkStatus(str _workStatus = workStatus)
{
workStatus = _workStatus;
return workStatus;
}
[DataMember('ErrorList')]
public List parmErrorList(List _errorList = errorList)
{
errorList = _errorList;
return errorList;
}
private static BASMSWorkHeaderCancellationResponseContract construct()
{
return new BASMSWorkHeaderCancellationResponseContract();
}
public static BASMSWorkHeaderCancellationResponseContract newFromTableRecord(str _workStatus, List _errorList)
{
BASMSWorkHeaderCancellationResponseContract contract = BASMSWorkHeaderCancellationResponseContract::construct();
contract.parmWorkStatus(_workStatus);
contract.parmErrorList(_errorList);
return contract;
}
}
Helper class:
class BASMSWorkHeaderCancellationHelper
{
str message,workStatus;
SysInfoLogEnumerator infoLogEnum;
SysInfologMessageStruct infoMessageStruct;
[AifCollectionTypeAttribute('return', Types::Class, classStr(BASMSWorkHeaderCancellationResponseContract))]
public List getWorkHeaderCancellation(str _workId , str _dataAreaId)
{
str workId = _workId;
str dataAreaId = _dataAreaId;
List workOrderList = new List(Types::Class);
WHSLoadLine loadLine;
boolean workCompleted;
WHSWorkTable worktable1,worktable,workTable2;
changecompany(dataAreaId)
{
List errorList = new List(Types::String);
try
{
ttsbegin;
worktable1 = WHSWorkTable::find(workId);
if (workId == '')
{
workStatus = '';
message = strFmt("Please enter the workid");
errorList.addEnd(message);
}
else if (!worktable1)
{
workStatus = '';
message = strFmt("Workid %1 is invalid Please enter a valid workid",workId);
errorList.addEnd(message);
}
else if (worktable1.WorkStatus == WHSWorkStatus::Cancelled)
{
workStatus = 'Cancelled';
message = strFmt("You cannot cancel work %1 because it has a status of Canceled.",worktable1.WorkId);
errorList.addEnd(message);
}
else if (worktable1.WorkStatus == WHSWorkStatus::Closed)
{
workStatus = 'Closed';
message = strFmt("You cannot cancel work %1 because it has a status of Closed.",worktable1.WorkId);
errorList.addEnd(message);
}
else if (worktable1.WorkStatus == WHSWorkStatus::Open)
{
WHSWorkTable::cancelWork(workId,true,false,UnknownNoYes::Yes);
workStatus = 'Cancelled';
}
worktable = WHSWorkTable::find(workId);
if (worktable.WorkStatus == WHSWorkStatus::Cancelled)
{
delete_from loadLine
where loadLine.ShipmentId == worktable.ShipmentId;
}
ttscommit;
}
catch(Exception::Error)
{
workCompleted = boolean::false;
infoLogEnum = SysInfoLogEnumerator::newData(infolog.infologData());
while(infoLogEnum.moveNext())
{
infoMessageStruct = SysInfologMessageStruct::construct(infoLogEnum.currentMessage());
str integrationMessage = infoMessageStruct.message();
errorList.addEnd(integrationMessage);
}
ttsabort;
}
BASMSWorkHeaderCancellationResponseContract workOrderData = new BASMSWorkHeaderCancellationResponseContract();
workOrderData = BASMSWorkHeaderCancellationResponseContract::newFromTableRecord(workStatus,errorList);
workOrderList.addEnd(workOrderData);
return workOrderList;
}
}
}
Service class:
class BASMSWorkHeaderCancellationService
{
[AifCollectionTypeAttribute('return', Types::Class, classStr(BASMSWorkHeaderCancellationResponseContract))] // name of the response contract class
// service method
public List getWorkHeaderCancellation(BASMSWorkHeaderCancellationRequestContract _contract) // name of the contract class
{
BASMSWorkHeaderCancellationHelper workOrderData = new BASMSWorkHeaderCancellationHelper();
str workId = _contract.parmWHSWorkId();
str dataAreaId = _contract.parmdataAreaId();
List workOrderList = new List(Types::Class);
workOrderList = workOrderData.getWorkHeaderCancellation(workId,dataAreaId);
return workOrderList;
}
}
Comments
Post a Comment