Wednesday, 28 November 2012



How to Generate Number Sequence in  MicroSoft Dynamics Ax /
Generate NumberSequence with X++ Code.



Step1:
 Create a new EDT  named as NoobId  should be string.

Step 2:
Suggest I have a table named NoobsTable and a field named NoobId, the extended data type for NoobId is NoobEDT.
I have a Form named  NoobsForm.
Step3:
 For example if the NoobsForm is located in Inventory managment Module you should find the class named NumberSeqReference_Inventory, then go to LoadModule method in that class and write the following at last:
    numRef.dataTypeId                =  typeId2ExtendedTypeId(typeid(NoobEDT)); //Extended     atatype related to NoobId.
    numRef.referenceHelp             =  literalStr("HelpText");
    numRef.wizardContinuous         = true;
    numRef.wizardManual             = NoYes::No;
    numRef.wizardAllowChangeDown    = NoYes::No;
    numRef.wizardAllowChangeUp      = NoYes::No;
    numRef.wizardHighest            = 99999999;
    numRef.sortField                = 1;
    this.create(numRef);

1. Create a new job with the following code and run it:
static void NumberSeqLoadAll(Args _args)
{
NumberSeqApplicationModule::loadAll();
}

Step4:

Then go to Table node and  NoobsTable, go to methods node then add a new method and write the following:
      server static NumberSequenceReference numRefNoobId()
      {
          return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(NoobEDT)));  //Extended datatype
      }
Exmaple:

server public static NumberSequenceReference  numRefHID()
{
    return NumberSeqReference::findReference(extendedTypeNum(HID));
}

Step5:
Ax2012 path:

Run the number sequence wizard by clicking on the Generate button in Organization administration | Common | Number sequences | Number sequences, and click on the Next button.

Ax2009 path:

Then go to Inventroy managment content pane --> Setup --> Parameters --> Number Sequences Tab 
now here you will see the Extended Data type NoobEDT and an empty Sequence number code, right click the empty lookup and click Go to the main table Form.
Add a new number sequence code in the opened form and save it [for example]:

Number sequence code: NoobNumberSeq
Name: NoobNumberSeq
Smallest: 1
Largest: 99999999
Next: 1
Format: Noob_########
InUse: Checked
Return to previous Form "Parameters" and choose NoobNumberSeq that we have just created it from Number sequence code lookup to NoobEDT Reference 

Step6:

 Go to NoobsForm -->classdeclaration

public class FormRun extends ObjectRun
{
    NumberSeqFormHandler    numberSeqFormHandler;
}

NoobsForm > >new Method

NumberSeqFormHandler numberSeqFormHandler()
{
if (!numberSeqFormHandler)
{
numberSeqFormHandler = NumberSeqFormHandler::newForm(
                                                     NoobsTable:: numRefHID ().NumberSequenceId,
                                                     element, NoobsForm.dataSource(),
                                                     fieldNum(NoobsTable, HID));

}
return numberSeqFormHandler;
}



Last thing to do is Go to NoobsForm --> Datasources node --> NoobsTable --> Methods, and override method  àcreate, delete and write the following:

public void create(boolean _append = false)
{
element.numberSeqFormHandler().formMethodDataSourceCreatePre();
super(_append);
element.numberSeqFormHandler().formMethodDataSourceCreate();
}

public void write()
{
super();
element.numberSeqFormHandler().formMethodDataSourceWrite();
}

public void delete()
{
element.numberSeqFormHandler().formMethodDataSourceDelete();
super();
}

Note: Just close once your Ax application and Open it.
Finally go to the form and create a new record and you will see your number is generated automatically and sequentially.
Note: go to NoobsTable and set NoobId field to( AllowEdit:No AllowEditOnCreate:No ) if you dont want anyone to edit the generated number.

Tuesday, 27 November 2012

How to Create Display Inventory Dimensions in Dynamics Ax or D365 F & O with X++



Display Inventory Dimensions in ax 2012


Add methods in Form  Class Declaration

public class FormRun extends ObjectRun
{
    InventDimCtrl_Frm_EditDimensions   inventDimFormSetup;
    ItemId  callerItemId;
}

void init()
{
    InventTable inventTable;
    super();
    if (isConfigurationkeyEnabled(configurationKeyNum(Retail))
        && element.args().caller()
        && element.args().record())
    {
        if (element.args().dataset() == tablenum(InventTable))
        {
            inventTable = element.args().record();
            callerItemId = inventTable.ItemId;
        }
    }
    element.updateDesign(InventDimFormDesignUpdate::Init);
}

Object inventDimSetupObject()
{
    return inventDimFormSetup;
}

void updateDesign(InventDimFormDesignUpdate mode)
{

    switch (mode)
    {
        case InventDimFormDesignUpdate::Init           :
            if (!inventDimFormSetup)
            {
                inventDimFormSetup  = InventDimCtrl_Frm_EditDimensions::newFromForm(element);
            }
            inventDimFormSetup.parmSkipOnHandLookUp(true);
            // do continue
        case InventDimFormDesignUpdate::Active         :
            inventDimFormSetup.formActiveSetup(InventDimGroupSetup::newItemIdProductDimensionsOnly
(DimenssionDisplayButtonTable.ItemId));
            inventDimFormSetup.formSetControls(true);
            break;

        case InventDimFormDesignUpdate::FieldChange    :
            inventDimFormSetup.formActiveSetup(InventDimGroupSetup::newItemIdProductDimensionsOnly

(DimenssionDisplayButtonTable.ItemId));
            inventDim.clearNotSelectedDim(inventDimFormSetup.parmDimParmEnabled());
            inventDimFormSetup.formSetControls(true);
            break;

        default : throw error(strFmt("@SYS54195",funcName()));
    }

}


Add methods in Form>>Datasource.

public boolean validateWrite()
{
boolean ret ;
;
DimenssionDisplayButtonTable.InventDimId  = InventDim::findOrCreate(InventDim).InventDimId;
ret = super() ;

//Display dimensions dialogDisplay dimensions dialogcreating, steps
    return ret;
  }


public int active()
{
int ret;
;
ret = super();
element.updateDesign(InventDimFormDesignUpdate::Active);
return ret;
}

public void modified()
{
 ;
super();
element.updateDesign(
InventDimFormDesignUpdate::FieldChange);
inventDim.clearNotSelectedDim(element.inventDimSetupObject().parmDimParmEnabled());

}

create a new menuitembutton set bellow the propertitys
 Caption  : DisplayDimensions
 Menuitemtype  : display
MenuItemName :   InventDimParmFixed