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);

reservation.updateNow();

Standard
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 w.r.to 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 lokesh_kant@hotmail.com

  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;

    #define.CurrentVersion(1)

    #localmacro.CurrentList

    x

    #endmacro

    }

    public void initParmDefault(){

    if(!x)

    x= “DEFAULT”;

    }

    public dataAreaId lastValueDataAreaId(){

    return curext();

    }

    public userId lastValueUserId(){

    return curuserid();

    }

    public UtilElementType lastValueType(){

    return UtilElementType::Form;

    }

    public identifiername lastValueElementName(){return this.name();}
    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;

    default:

    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(){

    super();

    x= xctrl.text();

    xSysLastValue::saveLast(element);

    }

Standard