Managers should be able to approve the Movement Journal through the Mobile App APIs

Managers should be able to approve the Movement Journal through the Mobile App APIs

class MK_InventJournalWFApprovalService { public MK_InventJournalWFApprovalResponse InventJournalTablePendingCount(MK_InventJournalRequest _request) { MK_InventJournalWFApprovalResponse response = new MK_InventJournalWFApprovalResponse(); List InventJournalList = new List(Types::Class); if (_request.parmEmail()) { UserId userId = this.getUserInfo(_request.parmEmail()).Id; InventJournalTable InventJournalTable; WorkflowWorkItemTable workFlowItemTable; select crosscompany count(RecId) from InventJournalTable join workFlowItemTable where workFlowItemTable.RefRecId == InventJournalTable.Recid && InventJournalTable.JournalType == InventJournalType::Movement && InventJournalTable.WorkflowApprovalStatus == InventJournalWorkflowApprovalStatus::PendingApproval && workFlowItemTable.Status == WorkflowWorkItemStatus::Pending && workFlowItemTable.UserId == userId && workFlowItemTable.RefTableId == tablenum(InventJournalTable); MK_InventJournalContract contract = new MK_InventJournalContract(); contract.parmCountRecords(InventJournalTable.RecId); InventJournalList.addEnd(contract); } response.parmInventJournal(InventJournalList); return response; } public MK_InventJournalWFApprovalResponse inventJournalPendingApproval(MK_InventJournalRequest _request) { MK_InventJournalWFApprovalResponse response = new MK_InventJournalWFApprovalResponse(); MK_InventJournalContract contract = new MK_InventJournalContract(); List inventJournalList = new List(Types::Class); InventJournalTable InventJournalTable; InventJournalTrans InventJournalTrans; MK_POWorkflowApprovalAppView workflowApprovalView; QueryBuildDataSource qbds, qbds1; QueryBuildRange qbr; Query query = new Query(); QueryRun qr; UserId userId; if (_request.parmEmail()) { userId = this.getUserInfo(_request.parmEmail()).Id; } query.allowCrossCompany(true); qbds = query.addDataSource(tablenum(InventJournalTable)); qbds.clearRanges(); qbds.clearLinks(); qbds.addSortField(fieldNum(InventJournalTable, JournalId), SortOrder::Ascending); qbds.addRange(fieldnum(InventJournalTable, JournalType)).value(QueryValue(InventJournalType::Movement)); qbds.addRange(fieldnum(InventJournalTable, WorkflowApprovalStatus)).value(QueryValue(InventJournalWorkflowApprovalStatus::PendingApproval)); if (_request.parmJournalId()) { qbds.addRange(fieldnum(InventJournalTable, JournalId)).value(_request.parmJournalId()); } qbds1 = qbds.addDataSource(tablenum(WorkflowWorkItemTable)); qbds1.addLink(fieldnum(InventJournalTable, RecId), fieldnum(WorkflowWorkItemTable, RefRecId)); qbds1.joinMode(joinmode::InnerJoin); qbds1.addRange(fieldnum(WorkflowWorkItemTable, RefTableId)).value(QueryValue(tablenum(InventJournalTable))); qbds1.addRange(fieldnum(WorkflowWorkItemTable, Status)).value(QueryValue(WorkflowWorkItemStatus::Pending)); if (_request.parmEmail() && userId) { qbds1.addRange(fieldnum(WorkflowWorkItemTable, UserId)).value(userId); } if (_request.parmEmail() && !userId) { qbds1.addRange(fieldnum(WorkflowWorkItemTable, UserId)).value('999999'); } qr = new QueryRun(query); qr.enablePositionPaging(true); qr.addPageRange(_request.parmStartPosition(), _request.parmPageSize()); while (qr.next()) { InventJournalTable = qr.get(tableNum(InventJournalTable)); select firstonly1 InventJournalTrans where InventJournalTrans.JournalId == InventJournalTable.JournalId; contract = new MK_InventJournalContract(); contract.parmJournalId(InventJournalTable.JournalId); contract.parmDescription(InventJournalTable.Description); contract.parmCreatedBy(InventJournalTable.CreatedBy); contract.parmCustAccount(InventJournalTable.MK_AccountNum); contract.parmReference(InventJournalTable.MK_Reference); contract.parmInvoiceId(InventJournalTable.MK_InvoiceId); contract.parmInvoiceDate(InventJournalTable.MK_InvoiceDate); contract.parmBrand(InventJournalTable.MK_Brand); contract.parmApprovedBy(this.getLastWorkflowApprovedBy(InventJournalTable.JournalId, InventJournalTable.DataAreaId)); contract.parmCostCenter(this.getCostCenter(InventJournalTable.DefaultDimension, 'costcenter')); contract.parmLegalEntity(InventJournalTable.DataAreaId); InventJournalList.addEnd(contract); } response.parmInventJournal(InventJournalList); return response; } public MK_InventJournalTransResponse InventJournalTrans(MK_InventJournalRequest _request) { MK_InventJournalTransResponse InventJournalTransResponse = new MK_InventJournalTransResponse(); List InventJournalTransList = new List(Types::Class); changeCompany(_request.parmDataAreaId()) { Query query = new Query(); QueryBuildDataSource qbds = query.addDataSource(tablenum(InventJournalTrans)); qbds.clearRanges(); qbds.clearLinks(); qbds.addSortField(fieldNum(InventJournalTrans, LineNum), SortOrder::Ascending); qbds.addRange(fieldNum(InventJournalTrans, JournalId)).value(_request.parmJournalId()); QueryRun qr = new QueryRun(query); while (qr.next()) { InventJournalTrans InventJournalTrans = qr.get(tableNum(InventJournalTrans)); InventJournalTable InventJournalTable = InventJournalTrans.inventJournalTable(); MK_InventJournalTransContract contract = new MK_InventJournalTransContract(); InventJournalTable = InventJournalTrans.InventJournalTable(); contract.parmJournalId(InventJournalTrans.JournalId); contract.parmLineNum(InventJournalTrans.LineNum); contract.parmItemId(InventJournalTrans.ItemId); if(InventJournalTrans.itemName()) {contract.parmProductName(InventJournalTrans.itemName());} else{contract.parmProductName(InventTable::find(InventJournalTrans.ItemId).productName(SystemParameters::getSystemLanguageId()));} contract.parmQty(InventJournalTrans.Qty); contract.parmUnit(InventJournalTrans.Unit); contract.parmcostPrice(InventJournalTrans.CostPrice); contract.parmCostAmount(InventJournalTrans.CostAmount); contract.parmCostCenter(this.getCostCenter(InventJournalTrans.DefaultDimension, 'costcenter')); contract.parmLegalEntity(strUpr(InventJournalTrans.DataAreaId)); contract.parmBrand(strUpr(InventJournalTable.MK_Brand)); InventJournalTransList.addEnd(contract); } InventJournalTransResponse.parmJournalLines(InventJournalTransList); } return InventJournalTransResponse; } public InventJournalTable findInventJournalTable(JournalId JournalId, DataAreaId _dataAreaId) { InventJournalTable InventJournalTable; if (JournalId) { select firstonly crosscompany InventJournalTable index hint JournalIdx where InventJournalTable.JournalId == JournalId && InventJournalTable.DataAreaId == _dataAreaId; } return InventJournalTable; } public str InventJournalApproval(MK_InventJournalRequest _request) { WorkflowWorkItemTable workflowWorkItemTable; InventJournalTable InventJournalTable; SysUserInfo sysUserInfo; UserInfo UserInfo; UserId userId; Description255 comment; UserInfo = this.getUserInfo(_request.parmEmail()); InventJournalTable = this.findInventJournalTable(_request.parmJournalId(), _request.parmDataAreaId()); comment = _request.parmComment() ? _request.parmComment() : strFmt("@MKLablel:ApprovedByUser", xUserInfo::find(false, sysUserInfo.Id).name); select firstonly1 workflowWorkItemTable where workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem && workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending && workflowWorkItemTable.RefTableId == tableNum(InventJournalTable) && workflowWorkItemTable.RefRecId == InventJournalTable.RecId && workflowWorkItemTable.UserId == UserInfo.Id; if (workflowWorkItemTable) { WorkflowWorkItemActionManager::dispatchWorkItemAction(workflowWorkItemTable, comment, userId, WorkflowWorkItemActionType::Complete, menuItemActionStr(InventTableApprovalApprove)); } else { return(strFmt("@MKLablel:RecordNotFound", InventJournalTable.JournalId, UserInfo.Id, '@MKLablel:SOWF08')); } return strFmt("@MKLablel:ApprovedWF", InventJournalTable.JournalId); } public str Reject(MK_InventJournalRequest _request) { WorkflowWorkItemTable workflowWorkItemTable; InventJournalTable InventJournalTable; SysUserInfo sysUserInfo; UserInfo UserInfo; UserId userId; Description255 comment; UserInfo = this.getUserInfo(_request.parmEmail()); InventJournalTable = this.findInventJournalTable(_request.parmJournalId(), _request.parmDataAreaId()); comment = _request.parmComment() ? _request.parmComment() : strFmt("@MKLablel:RejectedByUser", xUserInfo::find(false, sysUserInfo.Id).name); select firstonly1 workflowWorkItemTable where workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem && workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending && workflowWorkItemTable.RefTableId == tableNum(InventJournalTable) && workflowWorkItemTable.RefRecId == InventJournalTable.RecId && workflowWorkItemTable.UserId == UserInfo.Id; if (workflowWorkItemTable) { WorkflowWorkItemActionManager::dispatchWorkItemAction(workflowWorkItemTable, comment, userId, WorkflowWorkItemActionType::Return, menuItemActionStr(InventTableApprovalReject)); } else { return(strFmt("@MKLablel:RecordNotFound", InventJournalTable.JournalId, UserInfo.Id, '@MKLablel:SC27')); } return strFmt("@MKLablel:RejectedWf", InventJournalTable.JournalId); } private UserInfo getUserInfo(Email _email) { UserInfo userInfo; select firstonly1 userInfo where userInfo.networkAlias == _email; return userInfo ? userInfo : null; } public DirPartyName getLastWorkflowApprovedBy(JournalId _JournalId, DataAreaId _dataAreaId) { WorkFlowWorkItemTable workFlowWorkItemTable; InventJournalTable InventJournalTable; DirPartyName lastApproved; changecompany(_dataAreaId) { select firstonly1 UserId from workFlowWorkItemTable exists join InventJournalTable where workFlowWorkItemTable.RefRecId == InventJournalTable.RecId && workFlowWorkItemTable.RefTableId == tableNum(InventJournalTable) && workFlowWorkItemTable.Type == WorkflowWorkItemType::WorkItem && workFlowWorkItemTable.Status == WorkflowWorkItemStatus::Completed && InventJournalTable.JournalId == _JournalId; lastApproved = HcmWorker::worker2Name(HcmWorker::userId2Worker(workFlowWorkItemTable.UserId)); if (!lastApproved) {lastApproved = "None";} } return lastApproved; } public Name getCostCenter(LedgerDefaultDimensionValueSet _defaultDimension, str _dimension) { DefaultDimensionView DefaultDimensionView; select firstonly1 defaultDimensionView where defaultDimensionView.DefaultDimension == _defaultDimension && defaultDimensionView.Name like _dimension; return defaultDimensionView.dimensionDiscription(); } }

Comments

Popular posts from this blog

D365FO – AX – X++ –Refresh, Reread, Research, and ExecuteQuery

Create Inventory Journal through Code in D365FO X++

SalesLine Reservation in D365fo x++