Skip to main content

Introduction to When should you use code Elements instead of Frends Tasks

Choosing between code Elements and Frends Tasks

R
Written by Riku Virtanen
Updated over a year ago

When should you use code Elements instead of Frends Tasks

Code Elements are very useful in Processes, but you should always consider if something should be implemented using code Elements or Tasks. A rule of thumb is that you should always use Tasks when you can, since you can hide much of the complex sections of integrations that aren't really relevant when looking at the whole Process. In addition, you are not able to add any dependencies to code Elements. If you need some dependency to implement some part of the Process, you need to develop a Custom Task unless there already is a Task that suits your needs.

Code Elements should be used for small things, such as assigning variables or setting values to variables. They are also good for executing small code steps, such as mapping some data to an object that you can then pass to a Task as a parameter which we saw in module 1.

Sometimes you need to execute multiple lines of code to implement some functionality. It is okay to implement some functionality that requires multiple lines of code using a C# Statement Element, but you should consider how much code you want to put in the Element. If the code is starting to grow, you should consider if it would be better to implement the C# Statement as a Custom Task. Frends is not an IDE, so development of big code blocks is hard and error prone in code Elements. In addition, if there are some errors in the code it might be tricky to debug the issue. If you create a Custom Task instead of a big C# Statement, you are able to test the code with unit tests to make sure that the code behaves as expected.

The next article is Introduction to Code Element

Did this answer your question?