evalBuf Function [AX 2012]

Updated: June 21, 2011

Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

Evaluates the input string of X++ code, then returns the result as a string.


str evalBuf(str expressionString)

Parameter

Description

expressionString

The string to be evaluated.

The new string that contains the result of the expression.

For example, an input of 2 + 4 results in the string 6, not in the integer 6.

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.

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();
        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]".
}

Announcements: To see known issues and recent fixes, use Issue search in Microsoft Dynamics Lifecycle Services (LCS).
Show: