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

Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2015

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

0 votes
Answer accepted
Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2015

@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

1 vote
Phill Fox
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 22, 2015

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.

 

Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2015

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

Phill Fox
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 22, 2015

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.

Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2015

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

Phill Fox
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 22, 2015

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

Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2015

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

Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 30, 2015

Done :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events