Here's hoping that someone here can help out with this.
I am using script runner to do a query of an external database. Here are my exact requirements. On an existing JIRA issue, use two custom fields, both of type text. Field names are: Customer and PIN. Then query an external database, and return the result to another variable. There is a bit more than that, but for the purposes of this question this is good enough.
Using groovy and an example provided by Jamie, I am able to do a query on the other sql database. I can get the information that I need, if I hard code (statically define) in the two custom fields in the groovy script. That is, Customer = "Acme", and PIN = "1234". So I know that my connection and syntax are correct. What I can't figure out is how do I get and use the contents of my two custom fields, and pass them to the query instead of using a static defined variable.
Ultimately I am looking to have a workflow transition that the user can click on. The transition would execute the groovy script, which would then go out to the other database and do the query to verify the two fields in question and return to a third field a "Verified", or "Not Verified". Or behaviour similar to that.
Has anyone tried to do this before, or have any other suggestions on how I could accomplish this? I have plenty of examples of how to do a general query and update the custom field in JIRA, just not of how to 'use' the contents of an existing field. I'm sure that the information exists somewhere, I just haven't been able to find it so far.
Sounds like you've done the hard bit. You can retrieve and get custom field values using code like this. If you set this as the first post-function in your transition you shouldn't need to do much more than this.
package examples import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import org.apache.log4j.Logger def log = Logger.getLogger("com.onresolve.jira.groovy.MyScript") def MutableIssue issue = issue def customFieldManager = ComponentAccessor.getCustomFieldManager() def customerCf = customFieldManager.getCustomFieldObjectByName("Customer") def customer = issue.getCustomFieldValue(customerCf) // do database query... // set some value retrieved from the db def verifiedCf = customFieldManager.getCustomFieldObjectByName("Is Verified") issue.setCustomFieldValue(verifiedCf, "Verified")
I also assumed so, but it doesn't work for me. If I do it like this:
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager(); CustomField customText = cfm.getCustomFieldObjectByName("customText");
the customText reference is null. But if I do it like this:
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager(); CustomField customText = cfm.getCustomFieldObject("customfield_10000");
The problem is I don't want to do it like that because the id (customfield_10000) might be different when I deploy my plugin in production.
Any other advice? Thanks you :)
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!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
We're bringing product updates and pro tips on teamwork to ten cities around the world.Save your spot