convert Qty from a Unit to another Unit

protected Qty AI_Convert(Qty _QtyBatch,ItemId _itemId,SalesUnit _itemUnit,SalesUnit _salesUnit )
{
Qty salesQty;

salesQty = UnitOfMeasureConverter::convert(
_QtyBatch,
UnitOfMeasure::unitOfMeasureIdBySymbol(_itemUnit),
UnitOfMeasure::unitOfMeasureIdBySymbol(_salesUnit),
NoYes::Yes,
InventTable::itemProduct(_itemId));

return salesQty;
}

get last WorkFlow Comment. AX 2012

just add this code to tables method and drag it to the grid

display public server str aiComment()
{
WorkflowTrackingStatusTable trackingStatusTable;
WorkflowTrackingTable trackingTable;
WorkflowTrackingCommentTable trackingCommentTable;
WorkflowComment commentLoc = “”, comment;
;

while select trackingStatusTable where trackingStatusTable.ContextRecId == this.RecId join trackingTable
where trackingTable.WorkflowTrackingStatusTable == trackingStatusTable.RecId join trackingCommentTable
where trackingCommentTable.WorkflowTrackingTable == trackingTable.RecId && trackingCommentTable.Comment != commentLoc
{
comment = trackingCommentTable.Comment;
}

return comment;
}

by : _fiant

one PurchReq Line multiple PO

got client that really what one PR line can posting to multiple.

class RequisitionReleaseStrategy\Main

add this code below

//AIFD
if(cekProses)
{
    ttsBegin;
    for (purchReqLine = fds.getFirst(processMarkedRows) ? fds.getFirst(processMarkedRows) : _args.record(); purchReqLine; purchReqLine = fds.getNext())
    {
        select forUpdate purchReqLineLoc where purchReqLineLoc.RecId==purchReqLine.RecId;
        purchReqLineLoc.PurchLineCreated = false;
        purchReqLineLoc.RequisitionStatus = PurchReqRequisitionStatus::Approved;
        if(purchReqLineLoc)
        {
            purchReqLineLoc.update();
        }
    }
    ttsCommit;
}

Query based Report , add parameter dateFrom and dateTo//

//your language script here
[SysEntryPointAttribute(false)]
public void processReport()
{
    Query q;
    QueryRun qr;
    TransDate dateTo,dateFrom;

    AITransporterPerformanceReportContract contract = this.parmDataContract() as AITransporterPerformanceReportContract;

    dateTo = contract.parmDateTo();
    dateFrom = contract.parmDateFrom();

    delete_from aiTmp;
    q = this.parmQuery();
    q.dataSourceTable(tablenum(CustPackingSlipJour)).addRange(fieldnum(CustPackingSlipJour, DeliveryDate)).value(queryRange( dateFrom, dateTo));
    qR = new QueryRun(q);
    while(qR.next())
    {
        // your logic
    }
}

Vendor or Customer , Invoicing or Delivery Address

display Addressing  InvoicingAddress()
{
    Addressing address;
    DirPartyRecId party;
 
    party = CustTable::find(custConfirmJour.InvoiceAccount).Party;
    address = DirParty::getPostalAddressByType(party, LogisticsLocationRoleType::Invoice);
 
    if (!address)
        address = DirParty::getPostalAddressByType(party, LogisticsLocationRoleType::Delivery);
 
    return address;
}

source : http://dynamicsuser.net/forums/t/56107.aspx

Column BackColor Grid Form AX 2012

override method displayOptions in gridForm.

public void displayOption(Common _record, FormRowDisplayOption _options)
{
   #define.Red(255,0,0)
   TableNameDataSource   tableNameLoc;

   tableNameLoc = _record.data();

   //your logic if while etc
    
   _options.backColor(WinAPI:RGB2int(#Red);
   _options.affectedElementsByControl(element.controlId(CONTROL_NAME_IN_FORM));
   
   super(_record,_options);
   
}

contributor : _le

Print Sales Invoice via job X++ ax 2012

protected void printReportPdf(Common _record)
{
    args args = new args();
    CustInvoiceJour custInvoiceJour = _record;
    SRSPrintDestinationSettings printSettings;
    SalesInvoiceController controller = new SalesInvoiceController();

    args.record(_record);

    pdfPath = WinAPI::getTempPath() + custInvoiceJour.InvoiceId + ".pdf";

    // imposta nome report
    controller.parmReportName(ssrsReportStr(SalesInvoice, Report));

    // get print settings from contract
    printSettings = controller.parmReportContract().parmPrintSettings();

    // set print medium
    printSettings.printMediumType(SRSPrintMediumType::File);
    printSettings.fileFormat(SRSReportFileFormat::PDF);
    printSettings.overwriteFile(true);
    printSettings.fileName(pdfPath);

    // forzo che non vengano cambiati i parametri di stampa che gli passo io
    controller.DEVparmLockDestinationProperties(true);

    // suppress the parameter dialog
    controller.parmShowDialog(false);
    controller.parmArgs(args);

    // start operation
    controller.startOperation();
}

source : http://daxldsoft.blogspot.com/2012/07/print-salesinvoice-packingslip-or.html

print Sales Picking List via Jobs X++ AX 2012

static void Job6(Args _args)
{
    WMSPickingRoute         wmsPickingRoute;
    WmsPickingList_OrderPickController  aiController = new WmsPickingList_OrderPickController();
    WmsPickingList_OrderPickContract    aiContract   = new WmsPickingList_OrderPickContract();
    SRSTmpDataStore                     srsTmpDataStore;
 
    select firstOnly wmsPickingRoute where wmsPickingRoute.RecId==5637144577;//iisi sendiri jngn malas
    
    srsTmpDataStore.Value = Global::buf2Con(wmsPickingRoute);
    ttsbegin;
    srsTmpDataStore.insert();
    ttscommit;
 
    aicontroller.parmReportName(ssrsReportStr(WmsPickingList_OrderPick,Report));
    aicontroller.parmShowDialog(false);
 
    aiController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Screen);
   // aiController.parmReportContract().parmPrintSettings().printerName(“Xerox WorkCentre 3210 PCL 6 (Copy 1)”);
 
    aiContract.parmPickingRouteId(srsTmpDataStore.recid);
    aiContract.parmDocumentTitle(“x”);
    aiContract.parmShowRegistered(true);
    aiContract.parmShowActivated(true);
    aiContract.parmShowStarted(true);
    aiContract.parmShowPicked(true);
    aiContract.parmShowStaged(true);
    aiContract.parmShowLoaded(true);
    aiContract.parmShowCancelled(false);
    aiContract.parmPrintCopyOriginal(PrintCopyOriginal::Original);
 
    aiController.parmReportContract().parmRdpContract(aiContract);
    //aicontroller.startOperation();
 
    //aiController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
 
    // Run the report
    aiController.runReport();
}

get WorkFlow Approval Name

WHILE select workflowtrackingstatustable
join workflowtrackingtable
where workflowtrackingstatustable.ContextRecId == PurchTable.RecId //RecId of the record
&& workflowtrackingtable.TrackingContext == workflowtrackingcontext::WorkItem
&& workflowtrackingtable.TrackingType == workflowtrackingtype::Approval
&& workflowtrackingtable.WorkflowTrackingStatusTable == workflowtrackingstatustable.RecId
{
     info(strFmt(“%1″,SysWorkflowHelper::getDirPartyNameFromUserId(workflowtrackingtable.USER)));
}

or

display HcmWorkerName displayWorkflowApproverName()
{
    WorkflowTrackingTable tracking;
    WorkflowTrackingStatusTable trackingStatus;
    WorkflowWorkItemTable workitem;
    HcmWorkerName ret = "";
    UserInfo user;

    select tracking order by tracking.createdDateTime desc join trackingStatus
        where tracking.WorkflowTrackingStatusTable == trackingStatus.RecId
        && tracking.TrackingType != WorkflowTrackingType::Completion
        && ((tracking.TrackingContext == WorkflowTrackingContext::Step) || (tracking.TrackingContext == WorkflowTrackingContext::Task))
        && trackingStatus.ContextTableId==this.TableId && trackingStatus.ContextRecId == this.RecId;
    select workitem where workitem.RefRecId == this.RecId && workitem.RefTableId == this.TableId &&
        ((workitem.Status == WorkflowWorkItemStatus::Pending) || (workitem.Status == WorkflowWorkItemStatus::Delegated));

    return HcmWorker::find(HcmWorker::userId2Worker(workitem.UserId)).name();


}