Create Purchase Order via X++

void clicked()
{
    PurchTable  purchTable;
    PurchLine   purchLine;
    InventDim   inventDim;
    NumberSeq   numberSeq;

    //add by fanddy
    AxPurchTable    axPurchTable;
    AxPurchLine     axPurchLine;
    PurchFormLetter purchformLetter;
    //END

   //create PO Header
   purchTable.clear();
   purchTable.initFromVendTable(VendTable::find(TECPOGroupHeader.VendAccount));
   purchTable.DefaultDimension = InventTable::find(POGroupLine.ItemId).DefaultDimension;

   axPurchTable = axPurchTable::newPurchTable(purchTable);
   axPurchTable.parmPurchId(NumberSeq::newGetNum(PurchParameters::numRefPurchId()).num());
   axPurchTable.parmPurchaseType(PurchaseType::Purch);
   axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
   axPurchTable.parmAccountingDate(systemDateGet());
   axPurchTable.parmDeliveryDate(systemDateGet());
   axPurchTable.parmPurchStatus(PurchStatus::Backorder);
   axPurchTable.save();

   info(strFmt('Create PO %1', Purchtable.PurchId));

   //create PO Line
   purchLine.clear();
   purchLine.initValue();
   purchLine.initFromPurchTable(purchTable);
   purchLine.initFromInventTable(InventTable::find(POGroupLine2.ItemId));
   axPurchLine = AxPurchLine::newPurchLine(purchLine);
   axpurchLine.parmItemId('YOUR ITEMID');
   axPurchLine.parmPurchQty(YOUR QTY);
   axPurchLine.parmPurchPrice(YOUR PRICE);
   axPurchLine.parmInventDimId('YOUR INVENTDIMID');
   axPurchLine.save();

}

Advertisements

Auto Allocate Charges before auto Confirm Purchase Order

static void AutoAllocateCharges_beforeConfirmPO(Args _args)
{
    PurchTable purchTable;
    PurchFormLetter purchFormLetter;
    Args args = new Args();
    MarkupAllocation markupAllocation;

    select firstOnly purchTable where purchTable.PurchId=='1016-PO-14-000191';
    args.record(purchTable);
    //auto allocate charges
    markupAllocation = MarkupAllocation::newMarkupAllocation(args.record());
    markupAllocation.run(args.parmObject());
    
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
    purchFormLetter.update(purchTable, purchTable.PurchId);
}

Modify Controller Class for Query Based Report SSRS

public void prePromptModifyContract()
{
    //add a range in the report query  
      SrsReportHelper::addParameterValueRangeToQuery(this.getFirstQuery(),tableNum(SSRSReportDemo),fieldNum(SSRSReportDemo, RecId),SysQuery::value(this.parmArgs().record().RecId));
}

source : https://community.dynamics.com/ax/b/dynamics101trainingcenterax/archive/2014/01/30/using-controller-class-in-developing-ssrs-reports-in-microsoft-dynamics-ax-2012.aspx

get product-category Descendants example

public FreeText getDecendants(ItemId _itemid)
{
    str Decendants;
    EcoResProductCategory ecoResProductCategory;
    EcoResCategory        ecoResCategory;

    EcoResCategory        ecoResCategoryAscendants;

    select firstOnly ecoResProductCategory
    where
        ecoResProductCategory.Product==EcoResProduct::findByProductNumber(_itemid).RecId;

    select firstOnly ecoResCategory where ecoResCategory.RecId==ecoResProductCategory.Category;
    Decendants = ecoResCategory.Name;
    while select * from ecoResCategoryAscendants
            order by ecoResCategoryAscendants.NestedSetRight
                where   ecoResCategoryAscendants.CategoryHierarchy == EcoResCategory.CategoryHierarchy
                        && ecoResCategoryAscendants.NestedSetLeft  < EcoResCategory.NestedSetLeft
                        && ecoResCategoryAscendants.NestedSetRight > EcoResCategory.NestedSetRight
    {
       Decendants = strFmt("%1-%2",ecoResCategoryAscendants.Name,Decendants);
    }


    return Decendants;
}

call Manager Authentication Form for AX Retail POS

add reference library InteractionDefault.dll.

use this code below :

using Microsoft.Dynamics.Retail.Pos.Interaction

ManagerAccessForm formManager = new ManagerAccessForm();
var cekDialog = formManager.ShowDialog();
if (cekDialog == DialogResult.OK)
{
   // your logic
}

and dont forget to set ManagerAccessForm() to public on InteractionDefault project.

public ManagerAccessForm()
{
   InitializeComponent();
}