I have an issue picker field called 'Linked issue selection'. I'm trying to link the current issue to the issue selected in the picker field via a script. Here is the code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
def id = issue.getId()
def issuePickerField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Linked issue selection")
def issuePickerFieldValue = issue.getCustomFieldValue(issuePickerField) as Issue
def issuePickerFieldIssueId = issuePickerFieldValue.getId()
def linkManager = ComponentAccessor.getIssueLinkManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() as ApplicationUser
linkManager.createIssueLink(id, issuePickerFieldIssueId, 10003, 1, user)
The error rendered states:
"Error
We were unable to submit your request. Please refresh the page and try again. Note that this will clear your request details.
If you have already tried again, contact your Jira Administrator."
This post-function is located in the create transition as the 5th post-function. When the post-function is disabled the issue is created with no error.
Thank you
Thanks for your help Jack,
I was able to solve the problem by declaring the issuePickerFieldValue variable as a string. Then using that variable as the issue key to declare an issue object variable.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.ComponentManager
def id = issue.getId()
def issueManager = ComponentAccessor.getIssueManager()
def issuePickerField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12934")
def issuePickerFieldValue = issue.getCustomFieldValue(issuePickerField) as String
def pickedIssueAsIssue = issueManager.getIssueObject(issuePickerFieldValue)
def issuePickerFieldIssueId = pickedIssueAsIssue.getId()
def linkManager = ComponentAccessor.getIssueLinkManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() as ApplicationUser
linkManager.createIssueLink(id, issuePickerFieldIssueId, 10003, 1, user)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mick,
What is the order of this postfunction? Could you try it to send it to the bottom and see if it works?
If not, please provide us the error thrown in the log when the postfunction is executed, this would help to underestand where the problem is.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Jack,
The postfunction is at the bottom in the 5th position of the create transition. The log shows:
"Time (on server): Mon Aug 12 2019 09:38:34 GMT-0400 (Eastern Daylight Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
No logs were found for this execution."
It appears to execute without failure from the logs, but the customer portal shows the error posted above, and the new issue is not linked to the issue selected with the issue picker field.
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are there any other custom post-function or validator?
Is the issue created if you remove this custom postfunction?
Try to figure out what the problem is by searching in the atlassian-jira.log file instead
Hint: You can view the location of the atlassian-jira.log in the 'File Paths' section of the system information page.
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.