static void TIDgetTax(Args _args) { TaxAmount tax; CustInvoiceTrans CustInvoiceTrans; ; CustInvoiceTrans = CustInvoiceTrans::findRecId(5637155209); tax = Tax::calcTaxAmount(CustInvoiceTrans.TaxGroup, CustInvoiceTrans.TaxItemGroup, CustInvoiceTrans.InvoiceDate, CustInvoiceTrans.CurrencyCode, CustInvoiceTrans.LineAmount, TaxModuleType::FreeTxtInvoice); info(strfmt('%1', tax)); }
CODE
marking inventTrans example code
public static void FNDMarkInventTrans(InventTransId _inventTransId,InventTransId _refInventTransId,InventQty _qtyTomark) { InventTrans issueInventTrans; TmpInventTransMark tmpInventTransMask; Map mapMarkNow; container con; real qty; Map mapTmp; MapEnumerator mapEnumerator; InventTransOriginId issueInventTransOriginId = InventTransOrigin::findByInventTransId(_inventTransId).RecId; InventTransOriginId receiptInventTransOriginId = InventTransOrigin::findByInventTransId(_refInventTransId).RecId; InventQty qtyToMark = _qtyTomark; ttsBegin; issueInventTrans = InventTrans::findByInventTransOrigin( issueInventTransOriginId); [con, qty] = TmpInventTransMark::packTmpMark( InventTransOrigin::find(issueInventTransOriginId), issueInventTrans.inventDim(), issueInventTrans.Qty); mapTmp = Map::create(con); mapEnumerator = mapTmp.getEnumerator(); while (mapEnumerator.moveNext()) { tmpInventTransMask = mapEnumerator.currentValue(); if (tmpInventTransMask.InventTransOrigin == receiptInventTransOriginId) { tmpInventTransMask.QtyMarkNow = qtyToMark; tmpInventTransMask.QtyRemain -= tmpInventTransMask.QtyMarkNow; mapMarkNow = new Map(Types::Int64, Types::Record); mapMarkNow.insert(tmpInventTransMask.RecId, tmpInventTransMask); TmpInventTransMark::updateTmpMark( issueInventTransOriginId, issueInventTrans.inventDim(), -qtyToMark, mapMarkNow.pack()); } } ttsCommit; }
reference code :
https://community.dynamics.com/ax/b/dynamicsaxnotesonthecuffs/archive/2013/01/08/marking-from-code-part-2
get Available budget example code
source code from form : BudgetControlStatistics
example code :
static void TIDF_getBudgetAvailable(Args _args) { //class and table BudgetControlStatisticsManager budgetControlStatsManager = new BudgetControlStatisticsManager(); //table BudgetTmpControlStatistics currentBudgetTmpControlStatistics; BudgetCycle budgetCycle; BudgetCycleTimeSpan budgetCycleTimeSpan; FiscalCalendar fiscalCalendar; DimensionAttributeValueCombination dimensionAttributeValueCombination; DimensionHierarchy dimensionHierarchy; //variable DimensionValue dim1; container conDimValue; MainAccountNum mainAccountNum; RecId ledgerDimension; //financial dimension mainAccountNum = "6100-1001"; dim1 = "5102"; select firstonly dimensionAttributeValueCombination where dimensionAttributeValueCombination.DisplayValue == strFmt("%1-%2",mainAccountNum,dim1) && dimensionAttributeValueCombination.LedgerDimensionType == LedgerDimensionType::BudgetControl; //budget cycle fiscalCalendar = fiscalCalendar::findByCalendarId("2016"); BudgetCycleTimeSpan = budgetCycleTimeSpan::findByNameAndCalendar("SEM",fiscalCalendar.RecId); BudgetCycle = budgetCycle::findBudgetCycleByDate(BudgetCycleTimeSpan.RecId,today()); currentBudgetTmpControlStatistics = budgetControlStatsManager.fillBudgetTmpControlStatistics(Ledger::current(), 'ALL', BudgetControlStatisticsPeriodOption::FiscalPeriod, BudgetBalanceType::Accumulated, BudgetCycle.RecId, dimensionAttributeValueCombination.RecId, 0, 0, true, NoYes::No, true); while select currentBudgetTmpControlStatistics { info(strFmt("%1 -- %2 ",currentBudgetTmpControlStatistics.PeriodStartDate,currentBudgetTmpControlStatistics.TotalFundsAvailableAmountMST)); } }
result :
Resume Workflow from x++ example code
example code :
static void TIDF_resumeWFOverTime(Args _args) { WorkflowTrackingStatusTable WorkflowTrackingStatusTable; HrsOvertime hrsOverTime; while select WorkflowTrackingStatusTable where WorkflowTrackingStatusTable.TrackingStatus == WorkflowTrackingStatus::Faulted && WorkflowTrackingStatusTable.WorkflowType == WorkflowTrackingStatusWorkflowType::Workflow && WorkflowTrackingStatusTable.ContextTableId == tableNum(HrsOvertime) { //consistency check valid data select firstOnly hrsOverTime where hrsOverTime.RecId == WorkflowTrackingStatusTable.ContextRecId; if(hrsOverTime) { Workflow::resumeWorkflow(WorkflowTrackingStatusTable.CorrelationId); } } }
check user workflow hierarchy by code x++
i found a nice code for checking user workflow hierarchy approver and solved the related error.
static void navax_workflowHierarchyTester(Args _args) { WorkflowTypeName workflowTemplateName = 'TIDEmploymentLeave'; //TrvExpTrans trvExpTrans; //TrvExpNumber trvExpNum = '000015'; //Expense id HcmEmploymentLeave hcmEmploymentLeave; str nodeId = '23511014'; //Starting worker id WorkflowHierarchyLevel level = 0; WorkflowContext workflowContext; SysWorkflowTable workflowTable; WorkflowLimitHierarchyProvider workflowLimitHierarchyProvider; WorkflowHierarchyProviderNode workflowHierarchyProviderNode; HRPWorkerLimit workerLimit = new HRPWorkerLimit(); HcmWorker hcmWorker; DirPersonUser dirPersonUser; RefRecId hcmPositionRecId; HcmPosition hcmPosition; container spendingCon, approvalCon; UserId userId; select firstOnly workflowTable where workflowTable.TemplateName == workflowTemplateName; select firstOnly hcmEmploymentLeave where hcmEmploymentLeave.HRSLeaveReqId == "LV-00635" ; workflowContext = WorkflowContext::newWorkflowContext( curext(), tableNum(hcmEmploymentLeave), hcmEmploymentLeave.RecId, workflowTable.WorkflowCorrelationId); workflowLimitHierarchyProvider = new WorkflowLimitHierarchyProvider(); //Level 1 while (nodeId && level < 20) //20 is just a fall back. In case it goes into an endless loop. { workflowHierarchyProviderNode = workflowLimitHierarchyProvider.getNextNode(nodeId, level, workflowContext); nodeId = workflowHierarchyProviderNode.getnodeId(); hcmWorker = HcmWorker::findByPersonnelNumber(nodeId); userId = DirPersonUser::findParty(hcmWorker.Person).User; hcmPositionRecId = HcmWorker::getPrimaryPosition(hcmWorker.RecId); hcmPosition = HcmPosition::find(hcmPositionRecId); spendingCon = workerLimit.getWorkerSigningLimit( hcmWorker.RecId, SourceDocumentRelationType::ExpenseReport, HRPLimitType::Spending, hcmPosition.PositionId); approvalCon = workerLimit.getWorkerSigningLimit( hcmWorker.RecId, SourceDocumentRelationType::ExpenseReport, HRPLimitType::Approval, hcmPosition.PositionId); info(strFmt("UserId: %1 | WorkerId: %2 | PositionId: %3 | ReportsToPosition: %4 | SpendingLimit: %5 | ApprovalLimit: %6", userId, hcmWorker.PersonnelNumber, hcmPosition.PositionId, hcmPosition.reportsToPosition(), con2Str(spendingCon), con2Str(approvalCon) )); level++; } }