Using Expressions in Frends Processes
Adding simple C# code and reference values to your Processes.
Because Frends is a low code platform, some programming is necessary sooner rather than later in the development process. For the simple use cases of transferring data and results from one shape to another within a Process, expressions are used.
Step by Step Tutorial Available
If you prefer more visual or interactive guidance on how to use expressions in Frends Processes, you can find a step-by-step walkthrough from your own environment's home page, under Onboarding by selecting "Tutorial 2a, Step 4: Using C# expressions in Process" tutorial.
Requirements
As the expressions are basically C# code and reference values are essentially C# variables or objects with a Frends flare, some programming skill or understanding may be recommended to get going with Expressions. We will cover here the basics of the different syntaxes and notations available to use with Expressions to get everyone started, but from there it will get more complex quite quickly, and you should look for a C# guide instead to get further.
You should also have the edit permissions to a Frends Tenant to be able to edit Processes.
What are Expressions?
Expressions in Frends are single lines of C# code that perform a singular task or operation with or without returning a value. In C# programming terms, it would be a single line of code that begins on a new line or after an assignment symbol, and ends to a semi-colon.
Here are some examples of Expressions, that could also be used in Frends. Note that any content on a line after two slashes (//) are comments and not actually part of the expressions, used to explain what the expression does.
// This returns the value of Process Variable MyVariable, without modification
#var.MyVariable
// This checks whether a string variable is empty or not
String.IsEmptyOrNull(#var.TextVariable)
// This combines an Environment Variable and a string together
#env.ExampleCRM.BaseUrl + "/api/v1/customers"
// This obtains a result value from a Task earlier in the Process
#result[My HTTP Request Task].Body
// Trigger reference values are the input values to a Process
// Dot is used to access a field from the parent object
#trigger.data.HttpBody
// Object fields can also be accessed using indices
#var.ObjectVariable["MyField"]Note that when using expressions in various input fields and with Handlebars in Frends Process, the semicolon that in standard C# code ends the expression or line, is usually not included and may even cause errors.
Only exceptions where semicolons are required are when defining a lambda expression, or preparing a whole C# statement using a C# Code Task. These use cases actually expect or accept a whole C# statement which contains multiple C# expressions, and as such requires the full use of C# syntax.
Where are Expressions used?
Expressions can be used in almost every input field available in the different shapes within a Frends Process. It's actually easier to list the items that generally don't use expressions in their input fields: Triggers generally do not accept C# code expressions in their input fields due to nothing having been done in the Process at that point yet, and C# Code Task shapes as they expect a full C# statement and not a single expression.
In order to use expressions in your Frends Processes correctly, you need to pay attention the type of the field. If the field's type is selected to be Expression, you can write out the C# expression directly and the code will receive syntax highlighting and will be executed as C# code during Process executions.

If the field's input type is selected to be Text, JSON, SQL or XML, the input values will not be executed as C# code even if that would be input there, but instead the content will be used as is. In this case, you can use Handlebars syntax ({{}}) to include C# expressions within your otherwise standard text content.

You can view the type of a input field by moving your mouse cursor over the field. It's also changeable for the most fields, except for the exceptions mentioned above, in which case the content should be text only.
Here's various examples of locations and use cases where expressions are commonly used.
Assign Variable shapes
Assign Variable shape, that has also been called as the Expression shape, is often used to either store a value to a Process Variable, hence the name of the shape, or to execute other short C# expressions to modify a value.

In this example, the Assign Variable shape is used to take in the incoming request payload value from the Trigger reference, and convert it into a JToken object that is easier to use within Frends Processes. JToken is part of Newtonsoft's JSON library for C# that Frends utilizes.
Although the Expression input field can have its type changed to Text or other input types, by default and most commonly it is used as Expression type field, allowing direct input of C# code expression.
As you can see in this example, assignment operator (= or equal sign) nor semicolon are not used in expressions in Frends.
When using Assign Variable shape and the Assign variable option is enabled like in the example picture, the result value of the Expression field will be stored into a Process Variable called Payload, and is usable afterwards in the Process as #var.Payload.
Task Input Fields
Task input fields are a common location where expressions are used, as Tasks are generally used alongside other data available in the Process as well as in the Frends Environment the Process is executed in.

In the picture you can see a combination of both Environment Variables, static string content and a Process Variable being used in combination form the URL for a HTTP Request Task. Although the field type is not shown, we can assume from the syntax highlighting and lack of Handlebars that the field type is Expression.
The result value for that field could be something like this during Process execution:
https://examplecrm.frends.com/api/customers?12345678After the HTTP Request Task, we might want to use the response from the called web service in another Task, in this case to parse the response string value into a JToken to use the content easier. All Tasks and many other shapes provide a result reference value, that can be used as #result[Task Name] later on in the Process.

Here's an example where the earlier Task's result reference value is being used in a text input field. As the input field's type is apparently set as Text, we see the use of Handlebars syntax that enables us to include C# code within that field.
Decision Shapes
Decision shapes, such as the Exclusive Decision, rely on an expression input field that results in a boolean value, meaning true or false. For these shapes the Expression field is always in expression type and cannot be changed.

As the result has to be a boolean value for this to pass the validation, you will most likely need to get familiar with boolean logic and operators in C# for these to work correctly. Here's a couple examples to get started.
// Standard equals operator, comparing whether the values on both sides are equal
#var.Variable == 100
// Not equals operator to make sure values are NOT equal
#var.Variable != 100
// "Or" operator to have two conditions with either one being true to result in true
#var.Variable == 100 || #var.Variable == 200
// "And" operator to require both be true to result in true
#var.Variable == 100 && #var.Another == 200
// "Not" operator to invert the result from true to false and vice versa
!(#var.Variable == 100)AI Connectors
In order to pass in Process data to the AI Connector shape, Handlebars and C# expressions are needed.

In this example, the details of a Customer that we obtained from a web service are passed in to the AI for generating a summary of the customer's information. AI Connector often has the User prompt field as a text field with the prompt provided as static text, and the variable content is then provided with Handlebars and C# expressions.
Learn More
As the expressions are C# code, the topic will run deep and the content turns quickly into quite technical. In order to get more familiar with the programming capabilities of Frends, you can check out these resources from our reference documentation:
Assign Variable shape
Code Task shape
Last updated
Was this helpful?

