As an organization grows, so does the complexity of its automation use cases. The expression builder node allows workflow designers to perform operations like adding numbers together, replacing a part of a string of text, comparing strings, manipulating date/date-time fields, and helping cater to these advanced automation needs. 


Expression node

 

Expression builder node helps users,

  • Build complex expressions and perform String, Date, Numeric and Logical operations on data within the workflow. 

  • Build conditions based on expressions and use the results in subsequent workflow nodes. 


How to use the Expression Node?



There are 4 sections in the Expression node:

  • Expected Output

  • Functions

  • Operators

  • Body

  • Placeholders

  • Test expression


Expected Output - The type of output that will be returned when the expression is evaluated. You can string together multiple functions and operators in a single expression, which will then be validated against the expected output.

Example: To calculate the due date of a ticket based on the joining date of an employee,  the expected output in the expression node should be Date format.


List of outputs supported

  • String

  • Number

  • Boolean (True/False)

  • Date 

  • Datetime


Body - Construct expressions in the body section using the functions and operators supported below. You can also combine them with liquid filters.


     


Functions- The expression builder supports a whole host of functions that you can use to perform, date, string, mathematical and logical operations on values from the workflow context. 


Example: max(5, 10) where max is a function. Check out the list of functions supported by the expression builder node here


Note: Enclose the date and string values in quotes eg: ‘2022-01-02’, ‘Freshservice’.


Operators-  Operators let you define the mathematical operations or the logical comparisons to be performed. Check out the list of operators supported here.


Placeholder - Use the Placeholder section (+ icon)  to insert values from the workflow context.

Note - Use ISO format while using date-based placeholders in expressions.



Test expression - Hit the Test Expression button to validate both syntax and outputs of your expression. If your expression uses placeholders, you can use this section to replace them with sample values to evaluate the expression. 




 Check out the below video for a detailed explanation of Expression Builder Node:



Sample Usecases

Usecase 1 - Set the due date of the ticket based on the employee join date 

For Employee Onboarding requests, the SLA of the ticket is determined based on when the employee joins. In this example, let’s take a look at how to set the due date of the ticket based on the employee’s join date. 





  1. To configure a workflow, navigate to Admin →  Helpdesk Productivity → Workflow Automator. Select service request is raised from the event block. 




  1. Drag and drop the condition block and select Ticket fields → Requested items→ Employee Onboarding service item.




  1. Use the Expression builder node to calculate the due date of the ticket based on the employee join date 



  1. Set the Expected output as Datetime since the ticket due date has both time and date components related to it. 




  1. Select the Functions tab and click on addDays function to add 12 days to the Employee start date addDays('{{ticket.ri_5_cf_start_date_iso}}',12)


Use the Employee start date (ISO format) placeholder while building the expression.

 Note- Enclose the date field in quotes. 


 


  1. To evaluate the expression with sample values use the Test expression section.



  1. Finally to set the output of this expression as the due date of the ticket drag and drop the action node.



Usecase 2 - Skip the approval for a request if the approver is same as the requester of the ticket.


In some cases, managers might raise service requests for their employees. The approval process can be skipped in such scenarios since the manager would be the requester of the ticket. 


Now let’s see how this can be configured using the Expression builder node. 




  1. Select service request is raised in the event block



  1. Pull in the condition block and click on the Build expression radio button to check if the approver is the requester of the ticket. Set the Expected Output as Boolean.


  1. Use placeholders to check if the Requester is the same as the Reporting Manager of the Requested For.

              ‘{{ticket.actual_requester.reporting_manager.name}}’== ‘{{ticket.requester.name}}’

                Note: Enclose the string placeholders with quotes.



  1. Use the Test expression section and sample values to evaluate your expression.



  1. Pull in the action node, to send an approval if the condition is not satisfied.



  1. Finally, add a note to the ticket if it satisfies the above condition.


Usecase 3 - Derive Risk Assessment Score for Changes 


The Risk score, enables Change managers to assess the risk level associated with a Change request. With the expression builder node, calculate the risk score for each change request automatically based on certain parameters.



Questions 

Choice 

Score

What environment will this change be implemented in?

Non-production

1

Production

3


Production change been completed with all applicable teams? 

Yes - performed testing

1

No -  Testing will not be performed 

3


What is the impact of this production change on applications?

Low

2

Medium

4

High

5


  1. Navigate to Admin → Field manager → Form fields to create respective fields in the change form.



  1. To configure the workflow, navigate to Admin→ Helpdesk productivity → Workflow Automator. Select change is created in the event block.


  1. To calculate the risk score based on the inputs given in the change form, pull in the Expression builder node and set the Expected output as Number. 


  1. Use the if function to add all the scores for each risk assessment question.


            Syntax: if(conditional_expression, expression_if_true , expression_if_false)


         expression_if_true - executes conditions set for True if criteria matches

         expression_if_false - executes condition set for False if criteria fails.


  Example- if('{{change.what_environment_this_change_will_be_implemented_in}}'=='Non-production', 1,0) +  if('{{change.what_environment_this_change_will_be_implemented_in}}'=='Production', 3,0)




  1. Finally, pull in the action node to set the output of the expression builder node as the risk score.