AX 2012, Development, Dynamics AX, Uncategorized

Reserve quantity by X++ code

Quick code snippet to reserve the quantity by X++

SalesLine locSalesline;

InventMovement inventmovement;

InventUpd_Reservation reservation;

inventMovement = InventMovement::constructNoThrow(locSalesline,InventMovSubType::None);

reservation = InventUpd_Reservation::newinventdim(inventMovement, InventDim::find(InventDimReserveFrom),-1*inventqty, false);


AX 2012, Development, Dynamics AX

How to Save SysLastValues on the form

you may find some instances where you want to save some additional data on the form a user. Following example shows how you can implement this coding pattern to save last values on the form.

For any specific Implementation related queries shoot your questions at

  1. Identify the list of┬ávariables┬áthat you want to save with user’s Usage data.
  2. Implement following code
    public class FormRun extends ObjectRun{

    str x;






    public void initParmDefault(){


    x= “DEFAULT”;


    public dataAreaId lastValueDataAreaId(){

    return curext();


    public userId lastValueUserId(){

    return curuserid();


    public UtilElementType lastValueType(){

    return UtilElementType::Form;


    public identifiername lastValueElementName(){return;}
    public identifiername lastValueDesignName(){return element.args().menuItemName();}
    public boolean unpack(container packedClass){int version = RunBase::getVersion(packedClass);;switch (version){case #CurrentVersion:[version,#CurrentList] = packedClass;

    return true;


    return false;


    return false;


    public void init(){super();// xctrl.text(“DEFAULT”);xSysLastValue::getLast(element);}
    public void run(){super();if(x)xctrl.text(x);// sxctrl is a string control on the form.}
    public container pack(){

    return [#CurrentVersion,#CurrentList];


    public void close(){


    x= xctrl.text();