Saturday 9 August 2014

Workflow Comment / Get workflow comments by code/ how to display workflow comments by code in Dynamics AX

display WorkflowComment displayMostRecentComment()
{
    WorkflowTrackingCommentTable        workflowTrackingCommentTable;
    WorkflowWorkItemTable               workflowWorkItemTable;
    WorkflowTrackingTable               workflowTrackingTable;
    HcmWorker                           hcmWorker;
    WorkflowComment    comment;
    UserInfo                            userInfo;
    Name                                name;

    if (hasFieldAccess(tableNum(WorkflowTrackingCommentTable), fieldNum(WorkflowTrackingCommentTable, Comment), AccessType::View))
    {
        select firstonly workflowWorkItemTable
                order by CreatedDateTime desc
                where   workflowWorkItemTable.RefTableId == this.TableId &&
                        workflowWorkItemTable.RefRecId   == this.RecId &&
                        workflowWorkItemTable.CompanyId  == this.DataAreaId &&
                        workflowWorkItemTable.Status     == WorkflowWorkItemStatus::Completed;

        workflowTrackingTable        = Workflow::findLastTrackingRecordForWorkItem(workflowWorkItemTable);
        workflowTrackingCommentTable = WorkflowTrackingCommentTable::findTrackingId(workflowTrackingTable.TrackingId);

        hcmWorker = HcmWorker::find(DirPersonUser::find(workflowTrackingTable.User).worker());
        if (hcmWorker)
        {
            name = strFmt("%1 (%2) : ", hcmWorker.name(), hcmWorker.PersonnelNumber);
        }
        else
        {
            select firstonly Name from userInfo where userInfo.Id == workflowTrackingTable.User;
            name = strFmt("%1 (%2) : ", userInfo.Name, workflowTrackingTable.User);
        }
        comment = strFmt("%1",datetime2str(DateTimeUtil::applyTimeZoneOffset(workflowTrackingCommentTable.CreatedDateTime, DateTimeUtil::getUserPreferredTimeZone()), DateFlags::FormatAll)) + ' ';
        comment += name;
        comment += workflowTrackingCommentTable.Comment;

    }
    return comment;
}

No comments:

Post a Comment