Hi,
I have the following script to update a field called 'bamboo plan'
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.IssueManager //IssueManager issueManager = ComponentManager.getInstance().getIssueManager(); //MutableIssue issue = issueManager.getIssueObject("ICTST-702"); def customFieldManager = ComponentAccessor.getCustomFieldManager(); def bp = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Bamboo Plan'}; def aco = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Account Class'}; def ac = issue.getCustomFieldValue(aco) if ((ac == 'Gold') || (ac == 'Bronze') || (ac == 'Silver') || (ac == 'Basic')) { def changeHolder = new DefaultIssueChangeHolder(); bp.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(bp), 'IOFF-OADTPAS'), changeHolder); issue.store(); }
On the same transition, I use the following script to call for the bamboo plan :
import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.MutableIssue import org.apache.commons.codec.binary.Base64; def user = "***"; def passwd = "*****"; def requestMethod = "POST"; def URLParam = [:]; IssueManager issueManager = ComponentManager.getInstance().getIssueManager(); MutableIssue Issue = issue; def issueID = Issue.getKey(); CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager(); CustomField bambooPlanObject = customFieldManager.getCustomFieldObjectByName("Bamboo Plan"); def userBambooPlan = Issue.getCustomFieldValue(bambooPlanObject)?.trim(); if (userBambooPlan != null ){ URLParam.put('bamboo.variable.jira_issue', issueID); def baseURL = "http://bamboo-ci.******.com:8085/rest/api/latest/queue/${userBambooPlan}"; def query = URLParam.collect { it }.join('&'); URL url; url = new java.net.URL(baseURL + "?" + query); def authString = user + ":" + passwd; byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); String authStringEnc = new String(authEncBytes); URLConnection connection = url.openConnection(); connection.setRequestProperty("Authorization", "Basic " + authStringEnc); connection.setRequestMethod(requestMethod); connection.setRequestProperty("Content-Type", "application/xml"); connection.setRequestProperty("Accept", "application/xml"); println("Connection URL :" + url); connection.connect(); println("status:" + connection.getResponseCode()) println("status:" + connection.getResponseMessage()) connection.getContent() } else { println ("bamboo plan field is empty, doing nothing.") }
the problem is that the script to call the bamboo plan is taking the old value before the transition although changing the field value is the first thing on the transition and running and starting the bamboo plan is the last thing ( even after the generic event )
Any idea what I'm missing ?
To answer your question as it stands, you probably just need to refresh the issue, eg:
issue = issueManager.getIssueObject(issue.id)
But instead of updating the value as you have, I would just use:
issue.setCustomFieldValue(cf, object)
this should work fine so long as your function comes before the ones the save and reindex the issue. If you do this, you should be fine without refreshing the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.