This is my service class code:
class ARFWorkflowServiceClass
{
public ARFWorkflowResponseClass submitToWorkflow(ARFWorkflowRequestClass contract)
{
boolean result = true;
List errors = new List(Types::String);
// Retrieve data from the request object
DataAreaId dataAreaId = contract.parmDataAreaId();
Main_AssetRequestID requestID = contract.parmMain_AssetRequestID();
boolean submitted = false; // Initialize as false
WorkflowVersionTable workflowVersionTable;
ARFWorkflowResponseClass response = new ARFWorkflowResponseClass(); // Create response object
try
{
Main_AssetRelocationHeader main_AssetRelocationHeader;
select firstonly requestID from main_AssetRelocationHeader
where main_AssetRelocationHeader.requestID == requestID;
if (1 == 1)
{
// Declare a new MCRHoldCodeTrans record (apply hold code)
Main_AssetRelocationHeader mmain_AssetRelocationHeader;
ttsbegin;
Workflow::activateFromWorkflowType(
WorkflowTypeStr(Main_ARFWorkflowType),
main_AssetRelocationHeader.RecId,
"Auto submit to workflow",
false,
curUserId());
// Update the workflow state
main_AssetRelocationHeader.ARFWorkflowStatus = ARFWorkflowStatus::Submitted;
main_AssetRelocationHeader.update();
submitted = true;
ttscommit;
}
else
{
// If not submitted
throw error(strFmt("failed, main_AssetRelocationHeader.ARFWorkflowStatus"));
}
}
catch
{
result = false;
//store errors
SysInfologEnumerator enumerator;
SysInfologMessageStruct msgStruct;
enumerator = SysInfologEnumerator::newData(infolog.cut());
while (enumerator.moveNext())
{
msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
//str errorMessage = strFmt("Error occurred: %1. main_AssetRelocationHeader: %2", msgStruct.message(), main_AssetRelocationHeader.ARFWorkflowStatus);
errors.addEnd(msgStruct);
}
//clear infolog
infolog.clear();
}
// Populate the response object with the results
response.parmErrors(errors);
response.parmResult(submitted);
return response;
}
}