Thursday, December 07, 2006

RunBuf (Evaluate), a wonderful function

"RunBuf" or in other development environment "evaluate" is a very nice function,
it helps me to save a lot of time for to develop a complex parameter table stucture

Call the function below with something like this
evaluateFormularWithCommon(SalesTable::find("252"), "SalesTable::find(_common.(fieldnum(SalesTable, SalesId))).SalesName")
you get the value of the field "Name" of the salesTable!

This looks like an stupid idea, but in some situation it could be very helpfully!
In our situation i have an common as table variable and an string which comes from an parameter table.
So the function returns the value of the formular-string in the Parameter-table. Very Nice!

static container evaluateFormularWithCommon(Common _common,
str _formular)
franz aigner 20061127
[Result (str), ReturnState (boolean)]
ReturnState: False --> Error, True --> OK

SalesTable::find(_common.(fieldnum(SalesTable, SalesId))).SalesName

in this sample, in the formula the reference of the source table must be the string '_common'
no semicolon at the end of the formular
the return value must be a string
XPPCompiler comp = new XPPCompiler();
str formular;

str toStr(AnyType _value)
if(typeOf(_value)==Types::String || typeOf(_value)==Types::VarString)
return strFmt("%1", _value);
return strFmt("%1", _value);
formular = 'AnyType evaluateFormularWithCommon(Common _common){return '+_formular+";}";

return [tostr(runbuf(formular, _common)), True];
return ["", false];

Navison Axapta Help:

Anytype RunBuf(str job, ...)

RunBuf executes the X++ job represented as text in job.
Job is a complete piece of X++ code and arguments can be specified by
appending them as arguments to RunBuf.
If the job returns a value, this value is the return value from RunBuf.
Otherwise RunBuf returns 0 (zero).

str myjob = "int myfunc(int i){ return i+7;}";
print runbuf(myjob,5);
will print the number 12 when executed.

This idea comes from tabax X++calculator!!


Max Belugin said...

there is also an evalBuf function

Muhammad Shujaat Siddiqi said...

but i have studied somewhere that both of evalBuf() and runBuf() requires developer privileges.

is that so??

Franz Aigner said...

I do not know, but it could be! Because the string must be compiled at run-time. Try it?!

cialis said...

In principle, a good happen, support the views of the author

klotylda said...

Hi! Could you please explain the difference between microsoft dynamics ax and axapta?
I'd be very grateful! :)