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

}

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 ...