Showing posts with label ax 2012. Show all posts
Showing posts with label ax 2012. Show all posts

Wednesday, August 22, 2018

ECORESCATEGORY Table in Dynamics-SSC -Vikas Mehta MULTISELECT

ECORESCATEGORY Table in Dynamics-SSC

Query to get the ecorescategory branches and nodes in ax 2012 

  this.parmQuery().dataSourceTable(tablenum(EcoResCategory), 1).clearRanges();
        categoryBuildRange = this.parmQuery().dataSourceTable(tablenum(EcoResCategory), 1).addRange(fieldnum(EcoResCategory, RecId));

        categoryEnum = category.getEnumerator();
        while (categoryEnum.moveNext())
        {
            categoryRecid = categoryEnum.current();
            select ecoResCategory where ecoResCategory.RecId == categoryRecid;
            currentLevel = ecoResCategory.Level;
            lowestlevel = ecoResCategory.getLowestLevel();
            categoryHierarchy = ecoResCategory.CategoryHierarchy;
            while(currentLevel <= lowestlevel)
            {
            while select ecoResCategoryChild where ecoResCategoryChild.CategoryHierarchy == categoryHierarchy
                                                && ecoResCategoryChild.Level ==  currentLevel
            {
                categoryRecid = ecoResCategoryChild.RecId;
                while select * from ecoResCat
                    order by ecoResCat.NestedSetLeft
                    where   ecoResCat.CategoryHierarchy == ecoResCategoryChild.CategoryHierarchy
                            && ecoResCat.NestedSetLeft  <= ecoResCategoryChild.NestedSetLeft
                            && ecoResCat.NestedSetRight >= ecoResCategoryChild.NestedSetRight
                {
                    if(ecoResCategory.RecId == ecoResCat.RecId)
                    {
                        select * from ecoResCategoryisLeaf
                            order by ecoResCategoryisLeaf.Name
                            where   ecoResCategoryisLeaf.CategoryHierarchy == ecoResCategoryChild.CategoryHierarchy
                             && ecoResCategoryisLeaf.ParentCategory  == ecoResCategoryChild.RecId
                                && ecoResCategoryisLeaf.IsActive == true;

                        if(!ecoResCategoryisLeaf)
                        {
                            allCategory.addEnd(categoryRecid);
                        }
                        break;
                    }
                }
            }
            currentLevel++;
        }


        }
 

Item lookup of ecorescategory in ui builder class

private void itemLookup(FormStringControl _control)
{
    Query query;
    QueryBuildDataSource qbdscategory,qbdsProductCategory,qbdsInvent,qbdsEcoProduct;
    container brandCon;
    int counter;
    RecId brandCategoryRecid,categoryRecid,segmentRecid;
    EcoResCategory category,segmentCategory;
    ;
    query = new query();
    qbdsInvent = query.addDataSource(tableNum(InventTable));
    qbdsEcoProduct = qbdsInvent.addDataSource(tableNum(EcoResProduct));
    qbdsEcoProduct.relations(false);
    qbdsEcoProduct.addLink(fieldNum(EcoResProduct,RecId),fieldNum(InventTable,Product));

    qbdsProductCategory = qbdsEcoProduct.addDataSource(tableNum(EcoResProductCategory));
    qbdsProductCategory.relations(false);
    qbdsProductCategory.addLink(fieldNum(EcoResProduct,RecId),fieldNum(EcoResProductCategory,Product));

    qbdscategory = qbdsProductCategory.addDataSource(tableNum(EcoResCategory));
    qbdscategory.relations(false);
    qbdscategory.addLink(fieldNum(EcoResProductCategory,Category),fieldNum(EcoResCategory,RecId));

 ECORESCATEGORY LOOKUP MULTISELECT

public void categoryLookup()
{
    Query           query = new Query(querystr(ProcCategoryEcoResCategory));
    int             mutiSelectTableNum = tablenum(EcoResCategory);

    container selectedFields = [mutiSelectTableNum, fieldname2id(mutiSelectTableNum, fieldstr(EcoResCategory, Name))];

    SysLookupMultiSelectCtrl::constructWithQuery(this.dialog().dialogForm().formRun(), categoryField.control(), query, false, selectedFields);
}

Method checkbox in Dynamics AX -Map Vikas Mehta

Method checkbox in Dynamics AX -Map ssc

Below is the method to select the records which are being selected as a method checkbox in the standard system in AX.
A map needs to be declared initially which needs to be initialized on init.


Map                                 gSelectedInventSum;
On init
gSelectedInventSum = new Map(Types::String, Types::Record);

this method needs to be written on the form design to get the selected record.
 
On selection
public edit boolean selectInventSum(
        boolean         _set,
        InventSum       _inventSum,
        boolean         _select)
{
    boolean inventSumSelected;
    InventDim dim = _inventSum.joinChild();

    inventSumSelected = gSelectedInventSum.exists(dim.inventBatchId);
    if (_set)
    {
        if (_select)
        {
            if (!inventSumSelected)
            {
                gSelectedInventSum.insert(dim.inventBatchId, dim);
            }
        }
        else
        {
            if (inventSumSelected)
            {
                gSelectedInventSum.remove(dim.inventBatchId);
            }
        }
    }

    return gSelectedInventSum.exists(dim.inventBatchId);
}
 Inorder to get the selected records on a button click use the below method
void clicked()
{
    int                     ret;
   InventDim               dim;
    InventDimParm           dimParm;
    MapEnumerator           enum;
    List                    receiptList;


    super();

        enum = gSelectedInventSum.getEnumerator();

        while (enum.moveNext())
        {
        dim = enum.currentValue();
        dim = InventDim::findOrCreate(dim);
        info(strFmt("item : %1,dim %2",inventSum.ItemId,dim.inventBatchId));

        }
 }
 Another way to get the items and  process further is as below
public int showContextMenu(int _menuHandle)
{
    int                     ret;
    inventSumSelector;
    receipt;
    InventDim               dim;
    InventDimParm           dimParm;
    MapEnumerator           enum;
    List                    receiptList;
             
    view = gCurrentView;

    item = gTree.getTreeItem(this.getSelection());
    if (gSelectedInventSum.empty())
    {
        dim = InventSum.joinChild();
        dim = InventDim::findOrCreate(dim);
        dimParm.initFromInventDim(dim);
        dimParm.InventBatchIdFlag = false;
         }
    else
    {
        enum = gSelectedInventSum.getEnumerator();
        receiptList = new List (Types::Class);
        while (enum.moveNext())
        {
            dim = enum.currentValue();
            dim = InventDim::findOrCreate(dim);
            dimParm.initFromInventDim(dim);
            receipt = //;
            receiptList.addEnd(receipt);
        }

    }
   
    return ret;
}

Wednesday, November 8, 2017

AX DEBUGGER NOT OPENING : DYNAMICS AX DEBUGGER IS BLANK BREAKPOINT

AX DEBUGGER NOT OPENING : DEBUGGER IS BLANK

Many a times we have faced a problem that, when we try to debug our X++ code, we simply put break points in our code and run the functionality, but it happens that the AX debugger opens but with a blank screen and the break point is not called.
So to overcome this issue,here are the few things that needs to be checked in order to properly run the debugger.

Make sure that enable breakpoint on server configuration as well as client configuration is checked.
On development environment, go to Tools--> Options--> Development. Make sure that the Debug mode is set to "When Breakpoint".
Make sure that the user must belong to the Microsoft Dynamics AX Debugging Users local group on the computer.

If not added, add the user to this group. After being added to the group, you'll need to logout of your windows session and log back in. Once you log back in, open AX, set your breakpoints, run your process and see if things work out for you.


Friday, December 23, 2016

AX 2012 TYPES OF KEYS : Surrogate, Alternate, Replacement, Primary, and Foreign Key

AX 2012 TYPES OF KEYS : Surrogate, Alternate, Replacement, Primary, and Foreign Key

 All keys are unique keys, meaning they disallow duplicate values and null values.

Primary key:

A primary key is one type of key. The other type of key is an alternate key. There is a maximum of one primary key per table, whereas a table can have several alternate keys. The primary key is usually the type of key that other tables, called child tables, refer to when a foreign key field in those other tables need a relational identifier.

Starting in Microsoft Dynamics AX 2012 the primary key for every new table is always enforced by an index that has exactly one field. The one field is usually an incremented number or a completely meaningless number that is generated by the system. For new tables the default is a primary key based on the RecId field. This is represented as the surrogate key in the user interface.

The following table describes the PrimaryIndex property and other major properties that are related to keys.

PrimaryIndex

The drop-down list contains the surrogate key plus every index on the table that has its AlternateKey property set to Yes.

CreateRecIdIndex

This property controls whether the system creates a unique index on the RecId field. The default value is Yes. This is the basis of the surrogate key.

No other field is added to this index, not even DataAreaId.

ReplacementKey

The drop-down list contains every index that has its AlternateKey property set to Yes.

You might change the default blank value to an index whose field values within each record provide a name or other moniker that is meaningful to people. If a ReplacementKey is chosen, its fields can appear on forms to helpfully identify each record.

The ReplacementKey should be a set of fields that represent the natural key.

ClusterIndex

The ClusterIndex value is given to the underlying Microsoft SQL Server database system as a performance tuning choice. This choice generally controls the physical sequence in which the records are stored in the underlying database.

Alternate Key

A table can have several alternate keys. Any one alternate key can switch to being the primary key, if the alternate key is comprised of only one field.

A table can reference the alternate key of another table. However, it is more common for a table to reference the primary key of another table. As an option, an alternate key can be chosen as the ReplacementKey of a table.

In practice each alternate key relies on a unique index for its implementation and enforcement. However, a unique index alone does not make an alternate key. TheAlternateKey property must be set to Yes to make a unique index be an alternate key.

The following table describes properties on the AOT node for an index.

AllowDuplicates

No means that the combined fields of the index must together make a value in each record which no other record has.

AlternateKey

Yes means that other tables can create foreign key relations that reference this key, as an alternative to referencing the primary key.

Indexes with two or more fields cannot have their AlternateKey property value set to Yes.

ValidTimeStateKey

A key that is marked as a valid time state key is not a candidate key for child tables to reference in their foreign key relations. Instead, this key is meant for managing date effective data in its own table.

The default is No. This field can be Yes only if the ValidTimeStateFieldType property is Yes on the table. Yes means this key contains the ValidFromand ValidTo fields.

The ValidTimeStateKey property cannot be set to Yes when the AlternateKey property is set to No.

ReplacementKey

A replacement key is an alternate key that the system can display on forms instead of a meaningless numeric primary key value. Each table can have a maximum of one replacement key.

The replacement key is chosen by setting the ReplacementKey property on the table. The drop-down list offers every alternate key as an available value.

 

Other Terminology for Keys

In Microsoft Dynamics AX, there are other terms that are used to describe table keys. These terms do not appear as property names in Microsoft Dynamics AX. These terms are described in the following table.

Foreign key

In Microsoft Dynamics AX, an AOT node under MyTable > Relations represents a foreign key. For more information, see the previous Relations section in this topic.

Natural key

A key whose value has meaning to people. Most replacement keys are natural keys.

Surrogate key

A key whose value has no meaning to people. A large number generated by the system, such as RecId, could be a surrogate key.

Unique key

A broad term that applies to primary keys and to alternate keys. It does not apply to foreign keys. This term emphasizes that all values for a given key must be unique within one table. All fields in a unique key must be not-nullable.


 

Thursday, December 22, 2016

EXPORT MODEL AND IMPORT MODEL FILES IN AX 2012 POWERSHELL AND CMD COMMAND PROMPT

EXPORT MODEL AND IMPORT MODEL FILES IN AX 2012 POWERSHELL AND CMD COMMAND PROMPT

Export an .axmodel file (Windows PowerShell)

  1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
  2. At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.
    Export Command Syntax :
    Export-AXModel –Model <name> -File <Filename.axmodel>
    Example : 
    Export-AXModel –Model SecurityModel -File C:\SecurityModel.axmodel


Import an .axmodel file (Windows PowerShell)
    1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
    2. At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.
    Import Command Syntax :
    Install-AXModel -File <Filename.axmodel> -Details
    Exmaple :
    Install-AXModel -File C:\SecurityModel.axmodel -Details

AX2012 AXUTIL commands to Import and Export Models

// Export
AxUtil export /model:"TestModel" /file:TestModel.axmodel

// Import
AxUtil import /file:TestModel.axmodel

C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities>AxUtil 

Thursday, November 10, 2016

DIALOG AND GET VALUE FROM DIALOG BOX USING AXAPTA X++ DYNAMICS AX

DIALOG AND GET VALUE FROM DIALOG BOX USING AXAPTA
Below is a Code how  to add dialog and get value from dialog box in dynamics Axapta. This is very simple you just need to create one method which is overridden method is dialog. Dialog method used to initialized dialog box for your form or report but without using get from dialog method you can not get value of dialog control.

So both method is important dialog and getfromdialog.

 public Object dialog(Object _dialog)
 {
 DialogRunbase dialog = _dialog;
 DialogGroup dateGroup;
 ;
 dateGroup = dialog.addGroup("");
 dateGroup.frameType(1);
 dateGroup.columns(2);
 fromdate = LedgerPeriod::findOpeningDate(systemdateget());
 toDate= systemdateget();
 dialog.addGroup("@SYS4083",dateGroup);
 dialogFromDate = dialog.addFieldValue(typeid(FromDate),fromDate,'',"@SYS67");
 dialog.addGroup("@SYS8828",dateGroup) ;
 dialogToDate = dialog.addFieldValue(typeid(ToDate),toDate,'',"@SYS67");
 dialog.addGroup("@SYS24500");
 dialogPageChange = dialog.addFieldValue(typeid(NoYes),pageChange,"@SYS15349","@SYS24755");
 dialogResetPage = dialog.addFieldValue(typeid(NoYes),resetPage,"@SYS9358","@SYS24756");
 dialog.addGroup("@SYS12608");
 dialogDetailSummary = dialog.addFieldValue(typeid(DetailSummary),detailSummary,'',"@SYS24757");
 dialogNoneBeginTransEnd = dialog.addFieldValue(typeid(NoneBeginTransEnd),noneBeginTransEnd,
 "@SYS1046","@SYS69638");
 dialogIncludeOpening = dialog.addFieldValue(typeid(NoYes),includeOpening,"@SYS23250","@SYS54008");
 dialogIncludeClosing = dialog.addFieldValue(typeid(NoYes),includeClosing,"@SYS14844","@SYS82258");
 dialog.addGroup("Opening Balance Account");
 dialogOpeningBalance = dialog.addField(typeId(LedgerAccount)
 ,"Opening Balance Account");
 return dialog;
 }
 public boolean getFromDialog()
 {
 ;
 fromDate = dialogFromDate.value();
 toDate = dialogToDate.value();
 detailSummary = dialogDetailSummary.value();
 pageChange = dialogPageChange.value();
 resetPage = dialogResetPage.value();
 noneBeginTransEnd = dialogNoneBeginTransEnd.value();
 includeOpening = dialogIncludeOpening.value();
 includeClosing = dialogIncludeClosing.value();
 OpLedgerAccount = dialogOpeningBalance.value();
 return true;
 }  

DYNAMICS AX CREATE CUSTOM NUMBER SEQUENCE X++ CODE SAMPLE

|| DYNAMICS AX NUMBER SEQUENCE ||

Suppose we want create number sequence for Test field on form in General  ledger module
Consideration: EDT-Test, Table-NumSeqTable and Form- NumSeqTable

Step1. Create new EDT with name Test
Step 2. Modify load module() method on  NumberSeqModuleLedger class

{
     datatype.parmDatatypeId(extendedTypeNum(Test));
     datatype.parmReferenceHelp(literalStr("Test"));
     datatype.parmWizardIsManual(NoYes::No);
     datatype.parmWizardIsChangeDownAllowed(NoYes::No);
     datatype.parmWizardIsChangeUpAllowed(NoYes::No);
     datatype.parmWizardHighest(999);
     datatype.parmSortField(30);
     datatype.addParameterType(NumberSeqParameterType::DataArea, truefalse);
     this.create(datatype);
}

Step 3.Create a method on LedgerParameters Table

     client server static NumberSequenceReference numRefTest()
{
     return NumberSeqReference::findReference(extendedTypeNum(Test));
}

Step 4.Write and run following job

static void NumberSeqLoadAll(Args _args)
{
         NumberSeqApplicationModule::loadAll();
}


Step 5.Then run the wizard

Organization Administration -> CommonForms -> Numbersequences->Numbersequences-> Generate -> run the wizard.

Step 6.Now we have to check the number sequence  is correctly working  for that write a job:

static void NumSeq(Args _args)
{
    NumberSeq  numberSeq;
    Test num;
    ;
    numberSeq = NumberSeq::newGetNum(ProjParameters:: numRefTest ());
    num = numberSeq.num();
    info(num);
}


Step 7.Now we want that Number Sequence in form level(Test Table):


 Write below code in class declaration  
public class FormRun extends ObjectRun
{
    NumberSeqFormHandler numberSeqFormHandler;

}

 Step 8.Write the NumberSeqFormHandler() in form methods node.

NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
    {
       numberSeqFormHandler = NumberSeqFormHandler::newForm(LedgerParameters:: numRefTest ().NumberSequenceId,
                                                             element,
                                                             NumSeqTable_DS,
                                                             fieldNum(NumSeqTable, Test)
                                                            );
    }
    return numberSeqFormHandler;
}


Step 9.Write the  Create(),Delete(),Write() , Validate Write(),Link Active() on the Data source methods node.
 Create() Method
void create(boolean append = false,
            boolean extern = false
{
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();

    super(append);

    if (!extern)
    {
        element.numberSeqFormHandler().formMethodDataSourceCreate(true);
    }
}

Delete() Method

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

Write()Method

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



Validate Write() Method

public boolean validateWrite()
{
    boolean         ret;
    ret = super();
    ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;
    if (ret)
    {
        NumSeqTable.validateWrite();
    }
    return ret;
}

Link Active() Method

public void linkActive()
{
    ;
    element.numberSeqFormHandler().formMethodDataSourceLinkActive();
    super();
}
Step 10.Finally add Close() method on form 
void close()
{
    if (numberSeqFormHandler)
    {
        numberSeqFormHandler.formMethodClose();
    }
    super();
}


Related Posts Plugin for WordPress, Blogger...