Develop > Expression Language > Expression Language examples with record properties

Expression Language examples with record properties

When using the Expression Language to build phrases, you need to refer to the current record's properties, which are the fields of the record. It is recommended to open the Fields tab in a separate window while you are building an expression elsewhere in the system.

Note When building an expression with record fields, make sure to use the field name rather than the field label.

Recipient lists

One common application of the Expression Language is building a list of recipients. The following are some examples of Expression Language phrases that return a recipient or a collection of recipients:

  • ${first_non_empty_value(entity.AssignedPerson.Id, entity.AssignedGroup.Id, entity.OwnedByPerson.Id, entity.ServiceDeskGroup.Id)}

    This expression from Incident Management uses the first_non_empty_value function which selects the first value from the given arguments that is not empty. In this case, the arguments are:

    • entity.AssignedPerson.Id. This expression returns the ID of the person related to the current record by the AssignedPerson relationship.
    • entity.AssignedGroup.Id. This expression returns the ID of the group related to the current record by the AssignedGroup relationship.
    • entity.OwnedByPerson.Id. This expression returns the ID of the person related to the current record by the OwnedByPerson relationship.
    • entity.ServiceDeskGroup.Id. This expression returns the ID of the person related to the current record by the ServiceDeskGroup relationship.
  • ${entity.IsRequestedForPerson.Id}

    This expression from Service Request Management returns the ID of the person related to the current record by the IsRequestedForPerson relationship.

  • ${entity.AffectsActualService.Owner, entity.IsOwnedByPerson}

    This expression from Change Management returns a collection of the following recipients:

    • entity.AffectsActualService.Owner. The owner of the actual service that is affected by the current change.
    • entity.IsOwnedByPerson. The person who is the owner of the current change.

Conditional expressions

Another application of the Expression Language is in building a conditional expression. The following are some examples of Expression Language phrases that return a boolean value based on the evaluation of the statements:

  • ${(current_update.ImpactScope.NewValue != current_update.ImpactScope.OldValue || current_update.Urgency.NewValue != current_update.Urgency.OldValue) && (entity.Urgency == 'TotalLossOfService' && entity.ImpactScope == 'Enterprise') }.

    This expression from Incident Management is a composite expression using the and and or functions. The individual phrases are:

    • current_update.ImpactScope.NewValue != current_update.ImpactScope.OldValue. This expression states that the new value of the ImpactScope field of the current record is not equal to the previous value of the field before it was updated.
    • current_update.Urgency.NewValue != current_update.Urgency.OldValue. This expression states that the new value of the Urgency field of the current record is not equal to the previous value of the field before it was updated.
    • entity.Urgency == 'TotalLossOfService' && entity.ImpactScope == 'Enterprise'. This expression states that the Urgency property of the current record is equal to 'TotalLossOfService' and its ImpactScope property is equal to 'Enterprise'.

    If at least one of the first two expressions is true and the third expression is true, the entire phrase is evaluated as true; otherwise it returns false.

  • ${current_update.BasedOnChangeModel.IsChanged && current_update.BasedOnChangeModel.OldValue != null}

    This expression from Change Management is a composite expression of two phrases using the and function:

    • current_update.BasedOnChangeModel.IsChanged. This expression evaluates whether the BasedOnChangeModel field of the current record has changed during the last data update.
    • current_update.BasedOnChangeModel.OldValue != null. This expression states that the previous value of the BasedOnChangeModel field of the current record before the last data update was not null.

    If both of these expressions are evaluated as true, the entire expression returns true; otherwise it returns false.

  • ${(entity.PhaseId != 'Escalate' && entity.PhaseId != 'Close' && entity.PhaseId != 'Log') && (current_update.ServiceDeskGroup.NewValue != current_update.ServiceDeskGroup.OldValue) && ( entity.ServiceDeskGroup != null) }

    This expression from Incident Management is a composite expression using the and function:

    • (entity.PhaseId != 'Escalate' && entity.PhaseId != 'Close' && entity.PhaseId != 'Log'). This expression is itself a composite using the and function. If the PhaseId property of the current record is not equal to Escalate, Close, or Log, then it returns true; otherwise it returns false.
    • (current_update.ServiceDeskGroup.NewValue != current_update.ServiceDeskGroup.OldValue). This expression states that the new value of the ServiceDeskGroup field of the current record is not equal to the previous value of the field before it was updated.
    • (entity.ServiceDeskGroup != null). This expression states that the ServiceDeskGroup property of the current record does not contain a null value.

    If all of these sub-expressions return true, the composite expression also returns true; otherwise it returns false.

Strings for comments or field values

An additional application of Expression Language is constructing a string to be used as a comment or a value for a field. The following are some examples of Expression Language phrases that return a string:

  • ${concat('Change Model replaced from "',current_update.BasedOnChangeModel.OldValue.DisplayLabel,'" to "',current_update.BasedOnChangeModel.NewValue.DisplayLabel,'"')}

    This expression from Change Management uses the concat function to create a comment. The string is composed of the following parts:

    • 'Change Model replaced from "'. This part of the expression creates the beginning of the comment.
    • current_update.BasedOnChangeModel.OldValue.DisplayLabel. This part of the expression returns the previous value of the DisplayLabel property of the BasedOnChangedModel field of the current record, before the last data update.
    • '" to "'. This part of the expression inserts the word "to" in the comment.
    • current_update.BasedOnChangeModel.NewValue.DisplayLabel. This part of the expression returns the new value of the DisplayLabel property of the BasedOnChangedModel field of the current record, after the last data update.

    When the comment is complete, it indicates that the Change Model was replaced from the old value to the new value.

  • ${substring(entity.Description, 0, min(80, length(entity.Description)))}

    This expression from Incident Management uses the substring function to form a string for a field value:

    • entity.Description. This expression returns the Description field of the current record, which serves as the input string.
    • 0. This argument indicates that the substring should begin from the beginning of the input string (position 0).
    • min(80, length(entity.Description)). This expression, which uses the min and length functions, indicates the number of characters to be included in the returned string. It returns the minimum of the two values: 80 or the length of the Description field of the current record.

    The string returned by the expression runs from the beginning of the record's Description field for 80 characters, or the entire field, whichever is shorter.

  • ${entity.CurrentApprovalDisplayComment}

    This expression returns the comments indicating the approval status of the current record.

Related Topics Link IconRelated Information