evalBuf Function
Dynamics AX 4.0
Evaluates the input string of X++ code, and then returns the result as a string.
str evalBuf(str expressionString)
If an attacker can control input to the evalBuf function, it presents a security risk. Therefore, this function runs under Code Access Security. Calls to this function on the server require permission from the ExecutePermission class. Ensure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this function.
The following example calls evalBuf to evaluate the supplied buffer.
static void JobEvalBufDemo(Args _args)
{
ExecutePermission perm;
str strCodeToExecute = "2 + 5";
str strResult;
;
perm = new ExecutePermission();
if (perm != null)
{
// Grants permission to execute the EvalBuf function.
// EvalBuf runs under code access security.
perm.assert();
// BP deviation documented.
print "Next will execute the string of code.";
pause; // Click Yes when asked to continue.
strResult = EvalBuf(strCodeToExecute);
// Close the code access permission scope.
CodeAccessPermission::revertAssert();
}
print "strResult is: [", strResult ,"]";
pause;
//
// Expected: "strResult is: [7]".
}
Community Additions
ADD
Show: