Do not print custom field in custom email if null

I have some custom fields I would like to print in a custom email generated as a Script Runner post function. BUT I only want the fields printed if value != null.

I am trying to use this template:

<%
    if (cfValues['Other Reason'] == 'Other') {
        out << "value is ${cfValues['Other Reason']}"
    }
    else {
        out << "test"
    }
%>

This is my actual code:

<%
    if (issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Client Case Number")) != null) {
        out << "Client Case Number:  ${issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Client Case Number"))}"
    }
    else {
        out << "Client Case Number: "
    }
%>

Right now this works when plugged into the builtin Script Runner Preview page, but not when plugged into my workflow.

Thank you,
Ben

2 answers

1 accepted

Not sure why I couldn' t get this to work as a work flow scripted post-function.

Copy and pasted into a scripted Listener, it works perfectly. That solves my issue.

The condition can be removed from body. Select "Has custom field value equal to" post function.

In the Condition box, you'd input

cfValues['Other Reason'].value.equals('Other')

And then add the email template in the box below. That was the simplest way I found to do what you are attempting, but regardless use the above to check the custom field value and it should work for you.

Thanks,

Aron

Aron,

Some but not all, of our customers use their own reference numbers for support tickets that get escalated to us. I was trying to get that number to appear in the subject line and body of the email if it existed, and a space to appear if it did not. This how we are currently doing these emails, which I was seeking to have JIRA automate.

For some reason this works exactly as expected using a scripted listener, but not as scripted post-function. But I'm happy as long as I get the desired functionality.

Thanks,

Ben

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

243 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you