runBuf Function

Executes the specified X++ code that is passed as a string.


anytype runBuf(str job,[anytype param])

Parameter

Description

job

The string that contains the code to run.

param

The parameters for the code being passed to the function; optional.

The return value of the code that was passed to the function; otherwise 0 if the code has no return value.

If an attacker can control input to the runBuf function, a security risk exists. 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 this method to run the contents of the supplied buffer. When this code is run, the integer 49 is sent to the print window.

void RunBufExample()
{
    str myJob = "int myfunc(int i) {return i+7;}";
    ExecutePermission perm;
    ;
 
    perm = new ExecutePermission();
    if (perm != null)
    {
        perm.assert();  // Assert the use of the dangerous API RunBuf.
        // BP deviation documented.
        print runBuf(myJob, 42);
        pause;
        CodeAccessPermission::revertAssert();
    }
}

Community Additions

ADD
Show: