Posted in ax 2012

Step name of Workflow

Below is the reference sample code to get the workflow step name.

public display str 25 stepName(PurchReqTable _purchReqTable)
{
container con;
PurchReqTable purchReqTable;
PurchReqTableHistory purchReqTableHistory;
WorkflowTrackingStatusTable workflowTrackingStatus;
WorkflowTrackingTable workflowTracking;
utcdatetime validDate = DateTimeUtil::utcNow();
WorkflowStepName stepName;
TransDate stepSinceDate;
PurchReqRequisitionStatus status;
TransDate statusSinceDate;
RefRecId workflowTrackingStatusRecId;
RefRecId workflowStepRecId;
UserInfo userInfo;
WorkflowTrackingTable workflowTrackingLocal,workflowTrackingLocal2,workflowTrackingLocal3;
WorkflowStepTable workflowstepTable;
RefRecId _purchReqTableRecId = _purchReqTable.RecId;

/* Get the current status */
select firstonly validTimeState(validDate)
CreatedDateTime, RequisitionStatus from purchReqTable
where purchReqTable.RecId == _purchReqTableRecId

outer join CreatedDateTime from purchReqTableHistory
where purchReqTableHistory.PurchReqTable == purchReqTable.RecId

outer join RecId from workflowTrackingStatus
order by workflowTrackingStatus.CreatedDateTime desc
where workflowTrackingStatus.ContextTableId == purchReqTable.TableId &&
workflowTrackingStatus.ContextRecId == purchReqTable.RecId;

/* line-item subworkflow */
select firstonly RecId, Name, CreatedDateTime, TrackingContext, TrackingType,WorkflowElementTable,WorkflowTrackingStatusTable,WorkflowStepTable from workflowTracking
order by workflowTracking.CreatedDateTime desc
where workflowTracking.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId;
if (workflowTracking.TrackingContext != WorkflowTrackingContext::LineItemElement ||
workflowTracking.TrackingType != WorkflowTrackingType::Creation)
{
/* Current step */
select firstonly RecId, Name, CreatedDateTime, TrackingContext, TrackingType,WorkflowElementTable,WorkflowTrackingStatusTable,WorkflowStepTable from workflowTracking
order by workflowTracking.CreatedDateTime desc
where workflowTracking.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId &&
workflowTracking.TrackingContext == WorkflowTrackingContext::Step &&
workflowTracking.TrackingType == WorkflowTrackingType::Creation;
}

if (purchReqTable != null)
{
status = purchReqTable.RequisitionStatus;
userInfo = xUserInfo::find(false, curUserId());

if (purchReqTableHistory != null)
{
statusSinceDate = DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(purchReqTableHistory.CreatedDateTime, userInfo.PreferredTimeZone));
}
else
{
statusSinceDate = DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(purchReqTable.CreatedDateTime, userInfo.PreferredTimeZone));
}

if (workflowTracking != null)
{
stepName = workflowTracking.Name;
stepSinceDate = DateTimeUtil::date(workflowTracking.CreatedDateTime);
workflowTrackingStatusRecId = workflowTrackingStatus.RecId;
workflowStepRecId = workflowTracking.WorkflowStepTable;
}
select firstOnly workflowTrackingLocal
where workflowTrackingLocal.TrackingType == WorkflowTrackingType::Return &&
workflowTrackingLocal.WorkflowElementTable == workflowTracking.WorkflowElementTable &&

workflowTrackingLocal.WorkflowTrackingStatusTable == workflowTracking.WorkflowTrackingStatusTable &&
workflowTrackingLocal.RecId > workflowTracking.RecId;

if (workflowTrackingLocal)
{
select firstOnly workflowTrackingLocal2
where workflowTrackingLocal2.TrackingType == WorkflowTrackingType::Creation &&
workflowTrackingLocal2.TrackingContext == WorkflowTrackingContext::Step &&
workflowTrackingLocal2.WorkflowElementTable == workflowTrackingLocal.WorkflowElementTable &&
workflowTrackingLocal2.WorkflowStepTable == workflowTracking.WorkflowStepTable &&
workflowTrackingLocal2.WorkflowTrackingStatusTable == workflowTrackingLocal.WorkflowTrackingStatusTable &&
workflowTrackingLocal2.RecId > workflowTrackingLocal.RecId;
}
if (!workflowTrackingLocal2)
{

 

select firstOnly workflowTrackingLocal2
where workflowTrackingLocal2.TrackingType == WorkflowTrackingType::Creation &&
workflowTrackingLocal2.TrackingContext == WorkflowTrackingContext::Task &&
workflowTrackingLocal2.WorkflowElementTable == workflowTrackingLocal.WorkflowElementTable &&
workflowTrackingLocal2.WorkflowStepTable == workflowTracking.WorkflowStepTable &&
workflowTrackingLocal2.WorkflowTrackingStatusTable == workflowTrackingLocal.WorkflowTrackingStatusTable &&
workflowTrackingLocal2.RecId > workflowTrackingLocal.RecId;

}

if (workflowTrackingLocal2 != null)
{

workflowstepTable = workflowstepTable::findRecId(workflowTrackingLocal2.WorkflowStepTable);
stepName = workflowstepTable.Name;
stepSinceDate = DateTimeUtil::date(workflowTrackingLocal2.CreatedDateTime);
workflowTrackingStatusRecId = workflowTrackingLocal2.WorkflowTrackingStatusTable;
workflowStepRecId = workflowTrackingLocal2.WorkflowStepTable;
}

}

return stepName;
}