using SysGlobalcache in a custom class - fails when run in batch

Hi,

Below is the original line in an existing custom class that is using

SysGlobalCache globalCache;

boolean isProforma;

isProforma = globalCache.get(curUserId(), ‘IsProforma’); // This line returns anytype object and it this case it is returning false when run on the client side as expected.

When running in a batch it is failing on the server and throwing the error. So, I change the line to below to add any2enum conversion run time funcation as below to convert the anytype to boolean.
isProforma = any2enum(globalCache.get(userId, ‘IsProforma’));

But it still fails and throwing an error something like below

Microsoft.Dynamics.Ax.Xpp.ErrorException: Exception of type ‘Microsoft.Dynamics.Ax.Xpp.ErrorException’ was thrown.

at Microsoft.Dynamics.Ax.MSIL.Interop.throwException(Int32 ExceptionValue)

at Microsoft.Dynamics.Ax.MSIL.Interop.ThrowCQLError(IL_CQL_ERR cqlErr)

at Microsoft.Dynamics.Ax.Xpp.CastHelper.ToBoolean(Object _value)

Is there a way to change the line of code to use a different conversion runtime function in the line of code isProforma = any2enum(globalCache.get(userId, ‘IsProforma’)); to avoid the error?

Thanks.

Dave

Something like this seems like working and I see the job is successfully running. Please let me know if there is a better way to rewrite the below snippet.

SysGlobalCache globalCache;

anytype isProforma;

isProforma = globalCache.get(curUserId(), ‘IsProforma’);

if(isProforma == NoYes::Yes)
{
isProforma = true;
}
else
{
isProforma = false;
}

It seems that the question is about AX 20125, therefore I’ll attach the version tag. Please do it yourself next time.

What type do you put into the cache? If it’s NoYes and not boolean, what if you declare isProforma as NoYes?

I assume you’re aware that you must generate CIL after making changes in X++, because batches run in CIL.