Using C# in Frends
There are several options provided which allow you to use C# code in Frends for example in:
Expression Element
Code Statement Element
Exclusive Decision Element
Inclusive Decision branch expression
Task parameters.
Here you can find simple examples for each of the options listed above. For more details about how to use the presented Elements check the corresponding course in Frends Academy.
C# code example in an Expression Element
An Expression executes one line of C# code to convert the current date and time to that of the Julian calendar. The value is set to dateJulian variable.
C# code example in a Code Statement Element
In the simple code example C# code converts the value of #trigger.data.number, which is string type, to integer. Next, the integer is converted into hexadecimal. The result type is a string. The value in hexadecimal string is returned and set to variable hexResult.
The amount of C# code is not limited. However, it is important to remember that the basic principle in Frends is to utilise the ready defined Tasks as often as possible, instead of coding Process logic. In case the code block grows in length and complexity you should consider creating a new custom Task out of it.
C# code example in an Exclusive Decision Element
The example checks if the productCategory property is empty or null and based on result the Process flow is branched to true or false branches of an Exclusive Decision Element.
C# code example in an Inclusive Decision branch
The example below converts a string to an integer and tests if the value is less than 1000. If the return value is true the Process execution proceeds to this branch of the Inclusive Decision expression.
C# code in task parameters
In the example below you can find a one line if clause as part of message parametrization. In case the inventory level result from Task ‘Check product inventory level’ is lower than 1000 JSON key gets value 0, otherwise the returned inventory level value.
The next article is Introduction to #result reference