Monday, December 7, 2020

how to write validateField method in Dynamics AX 7, d365

 

Hi guys, Today we see How to write validateField method in Dynamics AX 7, d365.


Check Below class.


class CustTable_Events

{

// Using On Events

    /// <summary>

    ///

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    [DataEventHandler(tableStr(CustTable), DataEventType::ValidatedField)]

    public static void CustTable_onValidatedField(Common sender, DataEventArgs e)

    {

        ValidateFieldEventArgs event = e as ValidateEventArgs;

        CustTable custTable = sender as CustTable;

    }


// Using Post EventHandler

    /// <summary>

    ///

    /// </summary>

    /// <param name="args"></param>

    [PostHandlerFor(tableStr(CustTable), tableMethodStr(CustTable, validateField))]

    public static void CustTable_Post_validateField(XppPrePostArgs args)

    {

        CustTable custTable     = args.getThis();   //getting table buffer

        FieldId fieldId              = args.getArg("p1"); // Variable buffer

        boolean ret                   = args.getReturnValue(); // get return value from standard method


        switch(fieldId)

        {

            case fieldNum(CustTable, AccountNum):

                if (strLen(custTable.AccountNum) <= 3)

                {

                    ret = ret && checkFailed("Account number should be more than 3 charecters.");

                }

                break;

        }

        args.setReturnValue(ret); // set the return value of this method to standard

    }


Keep Daxing!!

Friday, December 4, 2020

Remove special characters of Date and Time in ax 2012 X++

Hi guys, Today we see how to  Remove special characters of Date and Time in ax 2012 X++.


Run the below job.



 static void FormatDateTimeJob(Args _args)

{

    utcDateTime now = DateTimeUtil::utcNow();


    str formattedOutput;


    now = DateTimeUtil::applyTimeZoneOffset(

    now,

    DateTimeUtil::getClientMachineTimeZone());


    formattedOutput = DateTimeUtil::toFormattedStr(

        now,

        321,

        DateDay::Digits2,

        DateSeparator::None,

        DateMonth::Digits2,

        DateSeparator::None,

        DateYear::Digits2,


        TimeSeparator::Colon,

        TimeSeparator::Colon);


    info(formattedOutput);

    info(strRem(formattedOutput,":"+" "));

}

OutPut:







Keep Daxing!!