Add a post-function with a validator to trigger a webhook

Hello,

I'm wondering if is it possible add a simple validation , such as field is not null , in order to trigger a JIRA webhook into a post-function transition?

 

Something like this in high level code:

if(customfield_XXX != null){
	webhookManager.trigger("My Webhook");
}

 

Thanks Regards,

2 answers

1 accepted

@Phill Fox [Adaptavist],

 

Took a while since it was near by Christmas smile

This is what I've done, into the transition pos-function I trigger the webhook and into the JQL I added a condition to only aply on Bug issue type.

28-12-2015-06-26-57.png

Thanks,

Italo

Hi Italo,

Yes what you suggest is possible, but before you go down that route you also need to consider whether the consequence of an undefined value meaning your webhook is not triggered is your intention on the transition. 

Anyhow the following code is checking for a null customfield of type integer

 

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
Issue issue  = issue;
CustomField sourceCF = customFieldManager.getCustomFieldObjectByName("Source Field");
 
Integer sourceValue = issue.getCustomFieldValue(sourceCF);

if (! sourceValue)

{
    webhookManager.trigger("My Webhook");
}

 

If your customfield is not an integer then replace Integer with the appropriate entry.

 

Hello Phill, First I would like to thanks for your quick answer, Do you know witch class should I use in order to trigger the webhook? This below lines were a high level code, I'm not sure if there is a webhookManager in Jira API and if is it the correct way to trigger the webhook. webhookManager.trigger("My Webhook"); I'm searching into JIRA API https://docs.atlassian.com/jira/6.4.11/ Thanks

HI Italo Sorry I am not familiar with the format for Webhooks, I assumed you were familiar already with that part. So what I did was work through the online documentation and can see how they work - See https://developer.atlassian.com/jiradev/jira-apis/webhooks. This shows that once webhooks are registered they can be added as a standard post-function. No need to write any script in the post function. You can also set some JQL to check your status and customfield values. So I would put the JQL in of 'status = <value> AND customfield is EMPTY' as part of your definition and then your solution becomes a lot simpler. Sorry this does not fully answer your question and I would love to have the time to experiment and get a fully working webhook listener in place but hopefully this points you in the right direction.

Hello Phill, I thought that using the JQL won't work when the webhook is trigger through a transition but after few test I discover that I was wrong :) It has worked as a charm using JQL to filter when trigger the webhook, also it a clear way to maintain in the future! Thanks for your effort your answer really helped :D Italo Qualisoni

Hi Italo, Glad it all worked out for you.Perhaps you could share a screenshot (with sensitive information obscured) so that others can see how you did it? Phill

Sure, tomorrow I'll post here an example! Italo

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

181 views 0 4
Read article

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