Search This Blog

Tuesday 22 November 2016

X++ checking DateNULL in Microsoft Dynamics AX

Some times we need to check the date column either its NULL or not.

Below is the link that shows how to check either date column null or not.

https://dynamicsaxposed.wordpress.com/tag/null-date-in-x/

Thanks
Muhammad Zahid. 

Wednesday 9 November 2016

Error: Getting Enum Value in Container and assigning it to the Enum variable.

I just stop in one of the scenarios in which I was trying get the enum value from container and assigning it to the enum variable by converting its type from string to enum.

The code compiles well but at the run time it throws exception.


Below is the code that was causing an issue.

static void Job26(Args _args)
{
    container _bRMAccountTypes;
    BRMAccountType bRMAccountType;
    ;

    _bRMAccountTypes = [BRMAccountType::Business];

    bRMAccountType = str2Enum(bRMAccountType, conpeek(_bRMAccountTypes, 1));

    info(strfmt('%1', bRMAccountType));
}

After running it got the following exception.













To resolve this issue the simple solution is.

Do not type cast the enum value that you are getting from container and assign it directly to the enum variable.

like this.

static void Job26(Args _args)
{
    container _bRMAccountTypes;
    BRMAccountType bRMAccountType;
    ;

    _bRMAccountTypes = [BRMAccountType::Business];

    bRMAccountType = conpeek(_bRMAccountTypes, 1);

    info(strfmt('%1', bRMAccountType));
}

It will work fine and show the correct results:


















Thanks
Muhammad Zahid.