JMWE Cloud: Troubleshooting "unable to call <expression> which is undefined or falsey" errors

JMWE Cloud: Troubleshooting "unable to call <expression> which is undefined or falsey" errors

 Problem

A post-function that contains a Nunjucks script runs into errors calling a Nunjucks filter or expression. The error message suggests the expression is “undefined or falsey.”

 Solution

The error is typically caused by the object invoking the Nunjucks filter or expression being in a null state. Suggested updates to your Nunjucks code include:

  1. If working with an object in a list (for example, the last comment posted in an issue), check if the total number of comments is not 0 first:

    {% if issue.fields.comment.total > 0 %} {% set replacement = (issue.fields.comment.comments | last | field("body")).match(r/\~accountid:(.*)\]/)[1] | userInfo ( "displayName" ) %} {% endif %}
  2. If working with an existing variable, check that the variable is not null:

    {% if var != null %} {% set replacement = var.match(r/\~accountid:(.*)\]/)[1] | userInfo ( "displayName" ) %} {% endif %}

The above code snippets are just examples of corrected scripts. If you are having difficulty identifying the problem in your scripts, please open a ticket with Appfire Support so we can assist you.

 Related articles