public display name reviewerName() // get workflow reviewer Name
{
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;
WorkflowTrackingWorkItem workflowTrackingWorkItem;
WorkflowWorkItemTable workflowWorkItem;
WorkflowWorkItemQueueAssignee workItemQueueAssignee;
PurchReqReviewStatus reviewStatus;
Name reviewer;
select firstonly validTimeState(validDate)
CreatedDateTime, RequisitionStatus from purchReqTable
where purchReqTable.RecId == this.RecId
outer join CreatedDateTime from purchReqTableHistory
where purchReqTableHistory.PurchReqTable == this.RecId
outer join RecId from workflowTrackingStatus
order by workflowTrackingStatus.CreatedDateTime desc
where workflowTrackingStatus.ContextTableId == this.TableId &&
workflowTrackingStatus.ContextRecId == this.RecId;
select firstonly RecId, Name, CreatedDateTime, TrackingContext, TrackingType from workflowTracking
order by workflowTracking.CreatedDateTime desc
where workflowTracking.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId;
if (workflowTracking.TrackingContext != WorkflowTrackingContext::LineItemElement ||
workflowTracking.TrackingType != WorkflowTrackingType::Creation)
{
select firstonly RecId, Name, CreatedDateTime, WorkflowStepTable
from workflowTracking
order by workflowTracking.CreatedDateTime desc
where workflowTracking.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId &&
workflowTracking.TrackingContext == WorkflowTrackingContext::Step &&
workflowTracking.TrackingType == WorkflowTrackingType::Creation;
}
workflowTrackingStatusRecId = workflowTrackingStatus.RecId;
workflowStepRecId = workflowTracking.WorkflowStepTable;
select firstonly RecId, TrackingContext, TrackingType from workflowTracking
order by CreatedDateTime desc
where workflowTracking.WorkflowTrackingStatusTable == workflowTrackingStatusRecId;
if (workflowTracking.TrackingContext != WorkflowTrackingContext::LineItemElement ||
workflowTracking.TrackingType != WorkflowTrackingType::Creation)
{
select firstonly RecId, Type, UserId, CreatedDateTime from workflowWorkItem
order by workflowWorkItem.CreatedDateTime desc
where workflowWorkItem.Status == WorkflowWorkItemStatus::Pending
exists join workflowTrackingWorkItem
where workflowTrackingWorkItem.WorkflowWorkItemTable == workflowWorkItem.RecId
join workflowTracking
where workflowTracking.RecId == workflowTrackingWorkItem.WorkflowTrackingTable &&
workflowTracking.TrackingContext == WorkflowTrackingContext::WorkItem &&
workflowTracking.TrackingType == WorkflowTrackingType::Creation &&
workflowTracking.WorkflowTrackingStatusTable == workflowTrackingStatusRecId;
if (workflowWorkItem && (workflowWorkItem.Type == WorkflowWorkItemType::RequestChange ||
workflowWorkItem.Type == WorkflowWorkItemType::Return))
{
select userInfo where userInfo.id == workflowWorkItem.UserId;
reviewer = userInfo.name;
}
else
{
select RecId, Status, Queue, IsClaimed, UserId, CreatedDateTime from workflowWorkItem order by RecId desc
exists join workflowTrackingWorkItem
where workflowTrackingWorkItem.WorkflowWorkItemTable == workflowWorkItem.RecId
join workflowTracking
where workflowTracking.RecId == workflowTrackingWorkItem.WorkflowTrackingTable &&
workflowTracking.TrackingContext == WorkflowTrackingContext::WorkItem &&
workflowTracking.TrackingType == WorkflowTrackingType::Creation &&
workflowTracking.WorkflowStepTable == workflowStepRecId &&
workflowTracking.WorkflowTrackingStatusTable == workflowTrackingStatusRecId;
if (workflowWorkItem.Status == WorkflowWorkItemStatus::Completed)
{
reviewStatus = PurchReqReviewStatus::Approved;
}
else
{
reviewStatus = PurchReqReviewStatus::Pending;
}
if (workflowWorkItem.Queue && workflowWorkItem.IsClaimed == NoYes::No)
{
select User from workItemQueueAssignee
where workItemQueueAssignee.WorkitemQueue == workflowWorkItem.Queue;
select userInfo where userInfo.id == workflowWorkItem.UserId;
reviewer = userInfo.name;
}
else
{
select userInfo where userInfo.id == workflowWorkItem.UserId;
reviewer = userInfo.name;
}
}
}
return reviewer;
}