ScriptRunner RunFunction throws exception when incorrect number of arguments are passed

I am attempting to run a javascript function using the ScriptRunner class and get an exception if the number of arguments passed in as the second parameter of the RunFunction does not match the number of arguments expected in the javascript function I am attempting to execute. Is there a way for the ScriptRunner class to determine how many parameters the javascript function expects before the RunFunction procedure is called?

For instance I want to be able to do something like this:

ScriptRunner scriptRunner;

// Set up scriptRunner object

int num_of_parameters = scriptRunner.GetFunctionParametersCount(“Main”);

if(calculationArgsObjectList.Count == num_of_parameters)
{
scriptRunner.RunFunction(“Main”, calculationArgsObjectList.ToArray());
}
else
{
// Log error that an an incorrect number of arguments have been supplied to the “Main” function.
}

Hi Andrew,

Sorry for the late reply,

We looked at this problem, and it looks like with some small modifications of our TypeScript/JavaScript Scripter we can add a method to evaluate an expression within already parsed code, so you will be able to use javascript-like expression to evaluate number of parameters for a given function like this:

var argLen = scriptRun.ScriptHost.Evaluate(“Main.length”);

We will try to push an update to NuGet packages with this functionality shortly.

Kind regards,
Dmitry

Hi Andrew,

We have just published a new version(8.1.10) to NuGet, which now supports JavaScript expression evaluation, which you can use to obtain a number of parameters before calling the function.

Kind regards,
Dmitry