Validate digits only in a field | AX 2012 | D365fo

str     NameX = 'A99464363';
   
str     subst,keepnum;
#define.alphabets('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
#define.numbers('0123456789')
subst       =   substr(NameX,1,strLen(NameX));
keepnum     =   strkeep(substr(NameX , 1, strLen(NameX)), #numbers);
 
   
if (keepnum!=subst)
{
    Info(strFmt("%1",NameX));
    error('@DMS1678'); //Mobile number should be numeric
}
if(strLen(NameX) != 10)
{
    //ret =  checkFailed("@DMS1713");
    error('@DMS1713'); //Mobile Number should be 10 digits
}

//---------------------------------
public boolean validate()
{
    boolean                             ret;
    str                                 subst,keepnum;
    DmspartnerCreationRequestTable      partnerCreationRequestTableLoc;
 
    #define.alphabets('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    #define.numbers('0123456789')
 
    subst       =   substr(dmsPartnerCreationRequestTable.Mobile,1,strLen(dmsPartnerCreationRequestTable.Mobile));
    keepnum     =   strkeep(substr(dmsPartnerCreationRequestTable.Mobile , 1, strLen(dmsPartnerCreationRequestTable.Mobile)), #numbers);
 
 
    ret = super();
 
    if (ret)
    {
        if(strLen(dmsPartnerCreationRequestTable.Mobile) != 10)
        {
            ret =  checkFailed("@DMS1713"); //Mobile Number should be 10 digits
        }
 
        if((dmsPartnerCreationRequestTable.Mobile) && (keepnum!=subst))
        {
            ret = checkFailed("@DMS1678"); //Mobile number should be numeric
        }
 
        select PartnerCode,Mobile,RequestNumber,RecId from partnerCreationRequestTableLoc
                        where partnerCreationRequestTableLoc.Mobile == dmsPartnerCreationRequestTable.Mobile;
 
        if (partnerCreationRequestTableLoc.RecId)
        {
            ret = checkFailed(strfmt("Mobile number %1 is tagged with partner request %2",
                    partnerCreationRequestTableLoc.Mobile,partnerCreationRequestTableLoc.RequestNumber));
        }
    }
 
    return ret;
}
//---------------------------------

Backup All Projects or Changes Layer wise from AX 2012 AOT

Microsoft Dynamics AX 2012 is an incredible piece of software. It allows extreme flexibility for both end users and developers. That said, “With great power comes great responsibility,” as I believe Uncle Ben put it. Too often in Dynamics AX environments we find a high degree of customization with little knowledge of exactly what has been changed, where the changes were made, and who made the changes. In this blog, I will run through a simple process that shows how to generate a project and quickly obtain all changes that fit a user defined filter.

Use cases:

  • Find all objects that are in the USR layer for move to deeper layer
  • Quickly generate an XPO backup of all changes in a layer
  • Prove who has touched what objects
  • Any time you need a list of objects based on some definable criteria
  1. Login to Dynamics AX and navigate to the AOT Projects window
    • Speed access – Open Dynamics AX client and hit <Ctrl + Shift + P>
  2. Generate a new project which will be the container for the change list

3.     Select “Advanced Filter/Sort <Ctrl + F3>”


4.     Set values to one of the following then click “Select”

·       Create

o   Append

1.     Add new information to the existing project

o   Overwrite

1.     Regenerate project as a whole getting all objects

·       Groupings

o   None

1.     Do not group information, simply return a list of all objects

o   AOT

1.     Structure list of objects to match the structure of the AOT tree

o   Per User

1.     Structure list of objects to return objects grouped by modifying user

2.     This is not going to tell you who changed everything with 100% accuracy, but it is a reliable starting point and awesome for troubleshooting


            5. Enter your criteria

·       I generally find the Layer option most useful followed by the Modified date and time to the query


            6. Click “Ok” then “Ok” again to run the project


Viola! You now have a project listing all objects fitting your criteria without having to generate a custom report or spend hours combing through documentation!



Credit source: Spencer Coulter -rsmus.com

Try Catch | Get infolog message to store into a variable | Combine multiple infologs into one to store | AX 2012 | D365fo

 

To show a message in infolog, use methods error(), warning() and info() - e.g. error("Something is wrong") or warning("@SYS116847"). You may also need strFmt() to format the string.

If you want to throw an exception, simply put "throw" before error(), e.g. throw error("@SYS84785").




throw error("Excise warehouse does not exist in warehouse master.");

info(strFmt("@DMS2535",purchTable.PurchId));

info('An error occurred while creating PO. Please contact Helpdesk.');

poStagingErrorTable.ErrorLog     = strFmt("%1 %2", execDateTime,strRem(infolog.text(infologLine()),'\t'));

poStagingErrorTable.update();



//-------------------------

public static void maintainLog(Name _legacyReferenceNo, infoLogData _infoLogData = [""])
{
    PartnerCreationRequestTableLog          partnerCreationRequestTableLog;
    SysInfoLogEnumerator                    infoLogEnum;
    str                                     exceptionMessage;
    SysInfologMessageStruct                 infoMessageStruct;
    ;
 
    ttsBegin;
    partnerCreationRequestTableLog.LegacyReferenceNo    = _legacyReferenceNo;
    partnerCreationRequestTableLog.LogRemarks           = _infoLogData;
 
    infoLogEnum = SysInfoLogEnumerator::newData(_infoLogData);
 
    while(infoLogEnum.moveNext())
    {
        infoMessageStruct = SysInfologMessageStruct::construct(infoLogEnum.currentMessage());
        exceptionMessage += infoMessageStruct.message() + ',';
    }
    partnerCreationRequestTableLog.RequestRemarks = exceptionMessage;
    partnerCreationRequestTableLog.insert();
    ttsCommit;
}


//-----------------------------

private void processData()
{
    #OCCRetryCount
    System.Exception    ex;  //to handle exception
 
    try
    {
        this.getDataForDealerFromSql();
    }
    catch(Exception::Error)
    {
        if(appl.ttsLevel() >1)
        {
            ttsAbort;
        }
        DealerCreationUpdationRequestBatch::maintainLog(resultset.getString(4),infolog.cut());
        info('Dealer Creation/Updation Request Creation fail');
    }
    catch(Exception::Deadlock)
    {
        retry;
    }
    catch (Exception::UpdateConflict)
    {
        if (appl.ttsLevel() == 0)
        {
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw Exception::UpdateConflictNotRecovered;
            }
            else
            {
                retry;
            }
        }
        else
        {
            throw Exception::UpdateConflict;
        }
    }
    catch (Exception::CLRError)//N - system.exception declared on top of this method
    {
        ex = CLRInterop::getLastException();
 
        if(ex != null)
        {
            ex = ex.get_InnerException();
 
            if(ex != null)
            {
                error(strFmt('CLR Error : %1',ex.ToString()));
                DealerCreationUpdationRequestBatch::maintainLog(resultset.getString(4),infolog.cut());
                info('Dealer Creation/Updation Request Creation fail');
            }
        }
    }
}
 


//-------------------------------------

public void process()
{
    SHEQARCOMSalesOrderHeader headerCompany;
    str                       message;
 
    while select headerCompany
        group by headerCompany.Company, headerCompany.ProcessStatus
           where headerCompany.ProcessStatus == SHProcessStatus::NotProcessed
    {
        changeCompany(headerCompany.Company)
        {
            SHEQARCOMSalesOrderHeader header;
 
            header.clear();
            while select forupdate header
                             where header.Company       == headerCompany.Company
                                && header.ProcessStatus == SHProcessStatus::NotProcessed
            {
                try
                {
                    ttsbegin;
                  
                    message = this.checkValidate(header);
 
                    if(message != "")
                    {
                        header.ProcessStatus = SHProcessStatus::Error;
                        header.LogMessage    = message;
                        header.update();
                        ttscommit;
                        continue;
                    }
 
                    //Create Header
                    SalesTable salesHeader = this.createSalesHeader(header);
                       
                    //Create Lines
                    this.createSalesLine(salesHeader);
                       
                    // Confirm
                    this.salesConfirmation(salesHeader);
 
                    // Invoice
                    this.salesInvoice(salesHeader,header);
 
                    CustInvoiceJour custInvJourNew;
 
                    select firstonly custInvJourNew where  custInvJourNew.SalesId == salesHeader.SalesId;
                    // Auto Settlement
                    if(header.CreditNote == NoYes::Yes && header.OriginalInvoice)
                    {
                        CustInvoiceJour custInvJourOld;
                        select firstonly custInvJourOld where custInvJourOld.InvoiceId == header.OriginalInvoice;
 
                        SHEQARCOMSalesInvoiceProcessService::AutoSettlement(custInvJourOld, custInvJourNew);
                    }
                       
                    if (custInvJourNew)
                    {
                        header.CustInvoiceId = custInvJourNew.InvoiceId;
                        header.SalesStatus   = SalesStatus::Invoiced;
                        header.ProcessStatus = SHProcessStatus::Processed;
                        header.InvoiceJourAmount = custInvJourNew.InvoiceAmount;
                        header.LogMessage    = "@YTEQAR:SH_SOCreatedInvoicedSuccessfully";
                        header.update();
                    }
                    ttscommit;
 
                    SalesTable SalesTableloc;
                    select forupdate SalesTableloc
                        where  SalesTableloc.SalesId == salesHeader.SalesId;
 
                    if(SalesTableloc.RecId)
                    {
                        ttsbegin;
                        SalesTableloc.selectForUpdate(true);
                        SalesTableloc.SHInvoiceId = custInvJourNew.InvoiceId;
                        SalesTableloc.doUpdate();
                        ttscommit;
                    }
                }
                catch(Exception::Error)
                {
                    ttsabort;
 
                    ttsBegin;
                    header.LogMessage="";
                    SysInfologEnumerator sysInfologEnumerator = SysInfologEnumerator::newData(infolog.infologData());
                    while (sysInfologEnumerator.moveNext())
                    {
                        header.LogMessage += strFmt("%1", sysInfologEnumerator.currentMessage());
                    }
                    header.ProcessStatus = SHProcessStatus::Error;
                    header.update();
                    Info(strFmt("@YTEQAR:SH_ErrorOccurredforInvoice",header.InvoiceId));
                    ttsCommit;
                }
                catch(Exception::CLRError)
                {
                    ttsabort;
 
                    ttsBegin;
                    header.LogMessage="";
                    SysInfologEnumerator sysInfologEnumerator = SysInfologEnumerator::newData(infolog.infologData());
                    while (sysInfologEnumerator.moveNext())
                    {  
                        header.LogMessage += strFmt("%1", sysInfologEnumerator.currentMessage());
                    }
                    header.ProcessStatus = SHProcessStatus::Error;
                    header.update();
                    Info(strFmt("@YTEQAR:SH_ErrorOccurredforInvoice",header.InvoiceId));
                    ttsCommit;
                }
            }
        }
    }
}

Table Browser in Dynamics 365FO

Copy D365FO Table Browser URL /?cmp=usmf&mi=SysTableBrowser&tablename= URL :  https://usnconeboxax1aos.cloud.onebox.dynamics.com...