We need to save the issue id in a custom field before we move the ticket over. So i added a script to save the issue id when a ticket gets created. Here is my script.
import com.atlassian.jira.component.ComponentAccessor def customFieldManager = ComponentAccessor.getCustomFieldManager() def custom_ticket_id = issue.getKey() def cticketCf = customFieldManager.getCustomFieldObjectByName("Custom Ticket ID") issue.setCustomFieldValue(cticketCf, "${custom_ticket_id}")
For some reason this does not populate the custom field. The script seems to run without errors. Is there something wrong with my script ?
Your coe seems to be correct.
But when postfucntion is called? Is it aflter create issue one? Do you have "Save changes into database" postfucntion after it?
Postfunction is called after the create issue. The last post function in the list.
How do i add "Save changes into database" postfunction ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Edit workflow - select transition - open postfunction section - press "Add post function" button - select "Stores updates to an issue".
I also would reccomend to use this code to store changes since it is compatible with JIRA 7:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue issue.setCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Custom Ticket ID"), issue.getKey()) ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser() , issue , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
works as exepected with the
ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser() , issue , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build())
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure i its really necessary but i think you have to use issueService to update the issue.
Iam using it in my scripts and everythink is working fine.
import com.atlassian.jira.issue.Issue import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import org.apache.log4j.Category import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult import com.atlassian.jira.bc.issue.IssueService.IssueResult import com.atlassian.jira.issue.IssueInputParameters def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") log.setLevel(org.apache.log4j.Level.DEBUG) IssueService issueService = ComponentAccessor.getIssueService() CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser def optionsManager = ComponentAccessor.getOptionsManager() IssueInputParameters issueInputParameters = issueService.newIssueInputParameters() CustomField customLieferant = customFieldManager.getCustomFieldObject(10046L) CustomField customFreigabe = customFieldManager.getCustomFieldObject(10028L) //def issue = issueService.getIssue(user, "WAR-17")?.issue String lieferant = (String) issue.getCustomFieldValue(customLieferant) def cfConfig = customFreigabe.getRelevantConfig(issue) def optionTrue = ComponentAccessor.optionsManager.getOptions(cfConfig).getOptionForValue("True", null) def optionFalse = ComponentAccessor.optionsManager.getOptions(cfConfig).getOptionForValue("False", null) def changeHolder = new DefaultIssueChangeHolder(); def liefList = ['Test1', 'Test2'] log.debug("checkDistributor -> " + String.valueOf(issue) + " : Starte Lieferantenvergleich") liefList.find{ if (it == lieferant){ log.debug(it + " gefunden in " + String.valueOf(issue)); issueInputParameters.addCustomFieldValue(customFreigabe.id, optionFalse.getOptionId().toString()) return true; } log.debug("Lieferant: " + lieferant + " nicht in Liste") issueInputParameters.addCustomFieldValue(customFreigabe.id, optionTrue.getOptionId().toString()) return false; } log.debug(issueInputParameters.getCustomFieldValue(customFreigabe.getId()).toString()) UpdateValidationResult update = issueService.validateUpdate(user, issue.id, issueInputParameters) log.debug(user.toString()) if (update.isValid()){ IssueResult updateResult = issueService.update(user, update) if (updateResult.isValid()){ log.debug("Updating " + issue.getKey() + " succesful") } else { log.debug("Error in issueService.update of " + issue.getKey()) } } else { log.debug("Error in issueService.validateUpdate of " + issue.getKey() + ": " + update.getErrorCollection()) }
In my case i change radiobutton field but concept should be the same. Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok. I fixed it with ...
ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() ,issue , EventDispatchOption.ISSUE_UPDATED , false )
But now i have an issue with the following error ..
2017-02-21 15:06:16,744 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CM-419, actionId: 1, file: <inline script> java.lang.ClassCastException: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String at com.atlassian.jira.issue.customfields.impl.GenericTextCFType.getDbValueFromObject(GenericTextCFType.java:51) at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(AbstractSingleFieldType.java:138) at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:731) at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:448) at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:434) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:704) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:669) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:655) at com.atlassian.jira.issue.IssueManager$updateIssue.call(Unknown Source) at Script240.run(Script240.groovy:23)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Somewhere you are using something
"$variable"
(ie a GString). Just add a .toString() after the string.
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.