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,
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure, tomorrow I'll post here an example! Italo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Done :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.