Workflow - Code block

Studio being a no-code application you would not need to use any kind of code in most cases. However, at times you can achieve just the expected output only by using your custom code block and by passing certain parameters and using the values duly returned by the code block.

Studio provides the Code block that allows you to create the code block that can be used anywhere in the workflow. You can pass the parameter to the functions that you are using. You can add the Javascript code which can return the values to other function calls on your screen.

Let’s understand the workflow for adding a code block. Under Select Task or Connector, select Code Block and click Continue. Enter a self-explanatory name and description and click Next.

code block

Now add the code block details which include the Parameter (if any) and the Java script for the action to be performed. The output of this code block would be used in the other tasks as Taskname.OUTPUT.

Add a parameter and then assign the value that would be passed. You can then add your javascript and use ‘return’ to assign the value of the function to the respective output variable or field.

Once you have added the code you can test it by adding the Test Value. After you have ensured that the code block contains no syntax or logical error you can click Done.

You can make the function Asynchronous mainly to optimize the long-running workflows. You would also use the resolve or reject to return the values. You can also view the supported libraries.

supported library

Typically, once you add the code block, you would use its returned values in another task in the workflow. You can add a variable in that task to fetch the value returned by the code block using {{variable}} = codeblockname.OUTPUT.

The workflow should be linked to the Submit button. Hence, when the form is executed, the Workflow would be triggered. The values from the form (if any are required) would be sent as parameters to the code block and the codeblock would return the values which would then be displayed using the respective variable.

Thus you can use the code block to carry out such custom functions that are specific to your use case. It can be effectively used by passing appropriate parameters and using the return values for further action.

The Code block variable, however, cannot be used outside the code block. The values returned are also a part of the task where the function is getting called.

You can have a look at the video and the article here to know how to use the code block .