Interview Questions

Wednesday, May 14, 2014

Ax 2012 Exception handling Example for beginners

static void Customer(Args _args)
{
    Dialog dialog;
    DialogField dialogCust;
    DialogField dialogGrp;
    DialogField dialogCur;
    CustTable   custTable;
    ;
    dialog = new dialog("Create new Customer");
    dialogCust = dialog.addField(extendedTypeStr(AccountNum),"Customer Account");
    dialogGrp = dialog.addField(extendedTypeStr(CustGroupId));
    dialogCur = dialog.addField(extendedTypeStr(CurrencyCode));

    if(dialog.run())
    {
        try
        {
            CustTable.AccountNum = dialogCust.value();
            CustTable.CustGroup  = dialogGrp.value();
            CustTable.Currency   = dialogcur.value();
            if (!CustTable.validateWrite())
            {
                 throw error("Please Enter all required field");
            }
            else if(custTable.AccountNum == dialogCust.value())
            {
                    custTable.insert();
                    info("Record inserted Successfully");
               //  throw error("Record already exist ");
            }
            if(custTable.AccountNum != dialogCust.value())
                {
                    //custTable.insert();
                    //info("Record inserted Successfully");
                    throw error("Record already exist aaaa ");
                }
        }
        catch
        {
             info ("An error occered please Try again");
        }
    }


}

No comments:

Post a Comment