AX 2012: evalBuf – Evaluate string expression in X++
evalBuf Function is a very strong API in X++. We can quite easily evaluate complex algebraic expressions given in string and the result is also given back in string. This API should be used along with CodeAccessPermission. The downside of using this API is that the code using this function is not supported in CIL.
This is how we can use this API
static void JobEvalBufDemo(Args _args) { ExecutePermission perm; str strCodeToExecute = "2 + (5*10)"; str strResult; ; perm = new ExecutePermission(); if (perm != null) { perm.assert(); // Grants permission strResult = EvalBuf(strCodeToExecute); CodeAccessPermission::revertAssert(); // Revoke permission } info(strFmt("Result is: %1", strResult)); // info: "Result is: 52" }

This was originally posted here.
*This post is locked for comments