Thursday, December 29, 2016

Regular Expression in AX 2012

X++ code to validate Name using Regular Expression in AX 2012


public bool validateName(str _name)
{

    System.Text.RegularExpressions.Match regExMatch;
    bool                                 isValid;

    // verify that Name doesn’t contain bad special character like <>:”/\|?*
    // other characters used in the regular expression are part of regex syntax. 

    regExMatch = System.Text.RegularExpressions.Regex::Match(_name, @’^[^<>:"/\\|?*]*$);
   
    // return true if name matches the criteria otherwise return false
    isValid = regExMatch.get_Success();   

    return isValid;
}

X++ code to validate Mobile no. in Ax 2012

static void MobilennoValidation(Args _args)
{

    boolean ret;
    #define.alphabets('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    #define.numbers('0123456789')
    int len;
    str  subst,keepnum;
    str Mobile;
    Mobile = "9876543210";
    len = strLen(Mobile);
    subst= substr(Mobile,1,len);
    keepnum=strkeep(substr(Mobile , 1, len), #numbers);

    if(len!=10)
    {
         checkFailed("@DMS1713");
    }

    else if((Mobile)&&(keepnum!=subst))
    {
         checkFailed("@DMS1678");
    }
    else
    {
        info("Mobile no, is validated successfully");
    }
}


X++ code to cancel Sales order and Purchase orders in AX 2012



                   
X++ Code to cancel Sales order

static void DMSSOCancel(Args _args)
{
    SalesTable salestable;
    SalesUpdateRemain SalesUpdateRemain;

    changeCompany('f898')
    {

        salestable = salestable::find("F898-000460");

        SalesUpdateRemain::cancelRemainderOnOpenSalesLines(salestable);

    }
}


X++ Code to cancel Purchase order
static void DMSCancelPO(Args _args)
{
    PurchFormLetter Purch;
    PurchTable PurchTable;
    PurchCancel PurchCancel ;

    changeCompany("f898")
    {
        PurchTable =PurchTable::find("F898-000079");

        PurchCancel PurchCancel::construct();
        PurchCancel .parmPurchTable(PurchTable);
        PurchCancel .run();
    }

}

Friday, November 18, 2016

Product name is missing while importing Produtcs and products masters through DIXF in AX 2012

Hi folks,

Hope u guys are doing well,

After long gap today im going to tell small trick i.e

Product name is missing while importing Produtcs and products masters through DIXF in AX 2012

Solution : just go to Systemparameters table and open it and check the systemlanguageid field data whether the imported Product and Product master Language id and systemlanguageid is same or not,if not please make sure it should be same .

Keep Daxing Guys !!!

Have a great weekend !!!

Friday, September 23, 2016

X++ code to filter PurchTableListPage form ( here it filters only today's Purchase order)

Hi Folks,

Today lets say about how to filter PurchTableListPage form.

Note: here it filters only today's Purchase order 

just goto PurchTableListPageInteraction Class >>initializeQuery()

and write below code which is highlighted below,

Keep Daxing :) !!! 

public void initializeQuery(Query _query)
{
    Query                   query;
    QueryBuildDataSource    qbds;
    QueryBuildRange         rangeCompanyId;
    QueryBuildRange         rangeUserId;
    QueryBuildRange         rangeId;
    QueryBuildRange         rangeStatus,qbr;
    ProjInvoiceTable        projInvoiceTable;
    ProjTable               projTable;

    if (EP::isVendor())
    {
        EPQuery::makeMyVendorSelfServiceQuery(_query, tableNum(PurchTable));
    }

    // added by shiva
    if(this.listPage().listPageArgs().menuItemName()==menuitemDisplayStr(PurchTableListPage))
    {
        qbr = _query.dataSourceTable(tableNum(PurchTable)).addRange(fieldNum(PurchTable,CreatedDateTime));
        qbr.value(queryValue(today()));
    }

    // ended by shiva


    super(_query);

    if (this.listPage().listPageArgs() &&
        this.listPage().listPageArgs().externalRecord() &&
        this.listPage().listPageArgs().menuItemName() ==  menuitemDisplayStr(PurchTableListPage) &&
        this.listPage().listPageArgs().externalRecord().TableId == tableNum(PurchRFQTable))
    {
        purchRFQTable = this.listPage().listPageArgs().externalRecord() as PurchRFQTable;
        this.applyPurchRFQRange(_query, purchRFQTable);
    }
    else if (this.getListPageType() == PurchTableListPage::AssignedToMe)
    {
        qbds = _query.dataSourceTable(tableNum(PurchTable)).addDataSource(tableNum(WorkflowWorkItemTable));
        qbds.joinMode(JoinMode::ExistsJoin);

        qbds.addLink(fieldNum(PurchTable, RecId), fieldNum(WorkflowWorkItemTable, RefRecId));
        qbds.addLink(fieldNum(PurchTable, TableId), fieldNum(WorkflowWorkItemTable, RefTableId));

        rangeStatus = qbds.addRange(fieldNum(WorkflowWorkItemTable, Status));
        rangeStatus.value(queryValue(WorkflowWorkItemStatus::Pending));
        rangeStatus.status(RangeStatus::Locked);

        rangeCompanyId = qbds.addRange(fieldNum(WorkflowWorkItemTable, CompanyId));
        rangeCompanyId.value(queryValue(curext()));
        rangeCompanyId.status(RangeStatus::Locked);

        rangeUserId = qbds.addRange(fieldNum(WorkflowWorkItemTable, UserId));
        rangeUserId.value(queryValue(curUserId()));
        rangeUserId.status(RangeStatus::Locked);

        //The Id-range is only used to lock the query from the Ui
        rangeId = qbds.addRange(fieldNum(WorkflowWorkItemTable, Id));
        rangeId.status(RangeStatus::Locked);
        rangeId.enabled(false);
    }
    else if (this.listPage().listPageArgs() &&
             this.listPage().listPageArgs().externalRecord() &&
             this.listPage().listPageArgs().menuItemName() ==  menuitemDisplayStr(PurchTableListPageProject) &&
             this.listPage().listPageArgs().externalRecord().TableId == tableNum(ProjInvoiceTable))
    {
        projInvoiceTable = this.listPage().listPageArgs().externalRecord();
        qbds = _query.dataSourceTable(tableNum(PurchTable)).addDataSource(tableNum(ProjTable));
        qbds.relations(true);
        qbds.joinMode(JoinMode::ExistsJoin);
        qbds.addRange(fieldNum(ProjTable,ProjInvoiceProjId)).value(queryValue(projInvoiceTable.ProjInvoiceProjId));
    }
    else if (this.listPage().listPageArgs() &&
             this.listPage().listPageArgs().externalRecord() &&
             this.listPage().listPageArgs().menuItemName() ==  menuitemDisplayStr(PurchTableListPageProject) &&
             this.listPage().listPageArgs().externalRecord().TableId == tableNum(ProjTable))
    {
        qbds = _query.dataSourceTable(tableNum(PurchTable));
        qbds.clearDynalinks();

        projTable = this.listPage().listPageArgs().externalRecord();
        qbds = _query.dataSourceTable(tableNum(PurchTable)).addDataSource(tableNum(PurchLine));
        qbds.relations(true);
        qbds.joinMode(JoinMode::ExistsJoin);
        qbds.addRange(fieldNum(PurchLine,ProjId)).value(queryValue(projTable.ProjId));
    }
}

Monday, August 29, 2016

Automation Process in DIXF (How Execute target step Checkbox works in GetStagingData Process)

The Microsoft Dynamics AX 2012 Data Import/Export Framework(DIXF) is an AX module import and export data in Microsoft Dynamics AX. We often use it in data migration projects to load legacy data from old systems. I was wondering if I could use DIXF as an automated integration, without any customizations. I wanted to see if I could have a folder where new customers are dropped in a folder, and then the DIXF automatically picked up the file, and imported it.
My first step is to have a small and minimalistic Excel sheet, that users can paste in the new customer records. This is how my Excel sheet looks like:
Most of these customers exists from before, but the last record is a new customer that don’t exists in my database.
The recommended process of setting up an import/export process is described here.
The first step is to create a source data format:
I then determine what entity to use, and create a target entity
When I do this, the mapping is done automatically for me, and I don’t have to understand all the database related complexity.
My next step is to create the processing group

I then click on the Entities in the processing group, and I select my created entity and that I want to use my created Excel source data format. I also select a sample file to see if the mapping is OK.
I then just check the mapping from Excel to the staging format, and make the necessary corrections.
My next step is to go back to the processing group, and to make the necessary batch job for automatic processing.
As you see here, I set the “type” to Directory, that DIXF will scan for new files. I also specify directories for processing, completed and error. I have therefore created the following directory structure for each integration:
The other important thing is the “Execute target step”. This this used for also executing the step that transfers data from the staging table to the target tables.
I then want this to be work in batch, so I enable the batch processing.
And then I need to wait for an entire minute……… I then saw that the file was moved from the 1_new folder, and ended up in the ¤_Completed folder.
I also see in the execution history, that the files was imported into the staging tables, and then imported into the target tables.
In my customer overview, I now see that I have a new customer, but is also made sure that other related data as addresses, and phone etc was created.
This concludes how you can use DIXF to automatically import data. What I can now do to import data, is just to create my Excel file, and then dump it into the right folder (.\1_New), and then the batch system take care of the test.
If you wonder all entities that are “out-of-the-box” supported from Microsoft, then take a look here. If still something is missing, you can always ask a developer to assist in creating the DIXF entities you need.
Happy Importing !!!

Best example:Importing Vendors with Financial Dimensions through DIXF in AX 2012

Thursday, August 25, 2016

Error in AX 2012 : The value 6 is not found in the map.

Error in AX 2012 : The value 6 is not found in the map.

Solution : Please check the configuration key whether it is enabled or not regarding with respect to where the error is facing.

Example:
 Goto: USMF/Project Management and accounting/Area page/Setups/
Open >>Project Management and accounting Parameters 
When i close the above form it throws an error like "The value 6 is not found in the map."

--Then,i have gone through with debugging the process and found the Table ProjFundingSearchParameter is having zero records that's why we facing this error.
to have records in above table we need to enable configuration key follow below process

--Now, Goto >>USMF/System administration/Area page/Setups/Licensing
Open>>License configuration>>projectII>>Advanced funding (Check the Advanced funding) a and save it ,now DB will synchronize automatically.

After this process ProjFundingSearchParameter  table will have 7 records .





Wednesday, August 24, 2016

How CIL Works in AX 2012

http://axwonders.blogspot.com/2013/04/ax-2012-cil-how-does-it-work.html

In AX development, it is a bit confusing about the real meaning of “Compile”, “generate
 Full CIL or incremental CIL”,
Compile: -The compile is to convert x++ source code into p-code, it is in 2009
full CIL :-generate CIL is about to convert the p-code into CIL, referred to as the byte code which, at run time, is used by the CLR to convert into native code for execution on the computer. It is easier to understand that a full CIL generation involves converting all p-code into CIL, finally it converts to the binary Lang
Incremental CIL :-incremental CIL generation involves only the “changed” p-code artifacts that need  to be converted into target CIL. Incremental CIL would compile only the objects that were modified since the last incremental compilation.
Some X++ batch jobs can now complete in much less time. All X++ code that runs on the AX32.exe client still runs as interpreted p-code. However, all batch jobs now run as Microsoft .NET Framework CIL, which is often much faster than p-code.
The X++ developer must now complete the extra step of compiling X++ p-code to CIL. To compile p-code to CIL, right-click AOT, and then click Add-ins > Incremental CIL generation from X++.
Next, if the installation uses multiple instances of Application Object Server (AOS), all AOS instances must be stopped and then restarted. This causes the AOS instances to load the updated assembly.
Finally, a service or a batch job must run the X++ code that was compiled to CIL. Services and batch jobs now run only as CIL

Wednesday, August 17, 2016

DIXF error when click on preview button: Package Execution Failed Please Check Event Log in DMF Service Box

Solution : The Excel sheet data should be error free(i.e without warnings & errors in excel sheet data)

Note : DIXF supports only 64-bit excel.

Tuesday, August 2, 2016

X++ code for Import data from excel using all datatypes in ax 2012

Hi Reader's

Today i come up with an important concept i.e how to import data from excel using all datatypes in ax 2012,
here is the code .
Keep Importing !!! :)

static void ExcelImportwithAllDataTypes(Args _args)
{
        SysExcelApplication application;
        SysExcelWorkbooks workbooks;
        SysExcelWorkbook workbook;
        SysExcelWorksheets worksheets;
        SysExcelWorksheet worksheet;
        SysExcelCells cells;
        SK_Excel sk_excel;
        COMVariantType type;
        Name name;
        FileName filename;
        int row;
        str path;
        str filetype;
        int i;
        NoYes   NoYes;
        FileIoPermission perm;
        DocuValue docuvalue;
        #define.FileMode('W')
        ;

    //specify the file path that you want to read
    filename = "D:\\ReadExcel"; //path of excel


        perm = new FileIOPermission(filename, #FileMode);
        perm.assert();
        application = SysExcelApplication::construct();
        workbooks = application.workbooks();
        try
        {
            workbooks.open(filename);
        }
        catch (Exception::Error)
        {
            throw error("File cannot be opened.");
        }

        workbook = workbooks.item(1);
        worksheets = workbook.worksheets();
        worksheet = worksheets.itemFromNum(1);
        cells = worksheet.cells();
        //progress.setAnimation(#AviTransfer);
        try
        {
          
            do
            {
                row++;
                if (row >= 1)
                {
                    sk_excel.clear();
                    sk_excel.String             =       cells.item(row,1).value().bstr(); // string
                    sk_excel.Int64              =       any2int64(cells.item(row,2).value().double()); // int64
                    sk_excel.Integer            =       any2int(cells.item(row,3).value().double()); //int
                    sk_excel.Real               =       cells.item(row,4).value().double(); //real
                    sk_excel.Container          =       str2con( cells.item(row,5).value().bstr()); //container
                    sk_excel.Date               =       cells.item(row,6).value().date(); //date
                    sk_excel.DateTime                      =     DateTimeUtil::newDateTime(cells.item(row,7).value().date(),timeNow());// datetime
                    sk_excel.Guid               =       str2guid(cells.item(row,8).value().bstr()); //guid
                    sk_excel.Enum               =       str2enum(NoYes,cells.item(row,9).value().bstr());//enum
                    sk_excel.time               =       cells.item(row,10).value().time(); // time
                    sk_excel.insert();
                }
                type = cells.item(row+1, 1).value().variantType();
        }

        while (type != COMVariantType::VT_EMPTY);

        info('done');

    }
  catch(Exception::Error)

    {

        workbooks.close();

        CodeAccessPermission::revertAssert();
        application.quit();

        ttsabort;

    }

    workbooks.close();

    CodeAccessPermission::revertAssert();

    application.quit();

}


Export a copy of the standard user acceptance testing (UAT) database

 Reference link: Export a copy of the standard user acceptance testing (UAT) database - Finance & Operations | Dynamics 365 | Microsoft ...