You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The example shows this way is to get current date using script.
var scriptingManager = serviceProvider.GetService<IScriptingManager>();
var date = scriptingManager.Evaluate("js: new Date().toISOString()");
However, the IScriptingManager does not expose a method that accepts string only.
Maybe the example should be as follow? Not sure if there is an easier way.
var scriptingManager = serviceProvider.GetService<IScriptingManager>();
var engine = scriptingManager.GetScriptingEngine("js");
var scope = engine.CreateScope(_scriptingManager.GlobalMethodProviders.SelectMany(x => x.GetMethods()), serviceProvider, null, null);
var date = engine.Evaluate("js: new Date().toISOString()");
Also it may be helpful to explain how to evaluate parameters using code? For example, how can I get the AdminUsername?
Executing engine.Evaluate(scope, "js: parameters('AdminUsername')" throws an exception `parameters is not defined. I added the following code to get it to work. Not sure if this is the right/best way to do it
var engine = _scriptingManager.GetScriptingEngine("js");
var methodProviders = _scriptingManager.GlobalMethodProviders.SelectMany(x => x.GetMethods()).ToList();
var environment = new Dictionary<string, object>();
await _environmentProviders.OrderBy(x => x.Order).InvokeAsync((provider, env) => provider.PopulateEnvironmentAsync(env), environment, _logger);
methodProviders.AddRange(new ParametersMethodProvider(environment).GetMethods());
var scope = engine.CreateScope(methodProviders, _serviceProvider, null, null);
var adminId = engine.Evaluate(scope, "js: parameters('AdminUserId')");
var adminName = engine.Evaluate(scope, "js: parameters('AdminUsername')");
The text was updated successfully, but these errors were encountered:
The example in the docs on how to evaluate code on this page seems to be outdated or does not work.
The example shows this way is to get current date using script.
However, the
IScriptingManager
does not expose a method that acceptsstring
only.Maybe the example should be as follow? Not sure if there is an easier way.
Also it may be helpful to explain how to evaluate parameters using code? For example, how can I get the
AdminUsername
?Executing
engine.Evaluate(scope, "js: parameters('AdminUsername')"
throws an exception `parameters is not defined. I added the following code to get it to work. Not sure if this is the right/best way to do itThe text was updated successfully, but these errors were encountered: