Location>code7788 >text

Elsa V3 Learning Scripts

Popularity:777 ℃/2024-08-18 22:19:37

In the previous article, you can see that we often use JS scripts to get the value of a variable. In Elsa there is support for a variety of scripts, the most commonly used are basically JS scripts and C# scripts.
This article is to introduce the following two scripts to use.

Javascript

The javascript in ELSA is implemented through the package Jint. The JS maps to methods within C#. It is possible to predefine our Functions in the code, and the following code for defining JS can be found in the project.



In addition to the above built-in methods, we can also customize our own JS method mapping. For example, mapping C# types out can call extension methods.

public static void RegisterType<T>(this ITypeAliasRegistry registry, string alias) => (typeof(T), alias);

Like this:

c#

c# scripts are compiled and executed dynamically.
The built-in WorkflowInputsProxy, for example, can be dynamically compiled to add our C# scripts.

We can also dynamically add support for our scripts in this way

Using Scripts

There are js and c# script nodes built into elsa for our testing.
We create a flow that holds the Run C# node to the canvas and write script (1).

Execute the workflow. You can see that our console outputs 1. The script was successfully run.

The RunJavaScript script is used in the same way, we have used it in several previous articles, so we won't repeat it here.

concluding remarks

This article describes the use of scripts in elsa. Through various scripts, we can flexibly orchestrate and use our workflow.