Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Referencing a just-created issue in ScriptRunner post script

Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2019

I have the following scenario: when an approver approves an issue, I have a post function that creates one or more subtasks and one or more issues of another type. I have a "Single Issue Picker" custom field on the other issue type. As I iterate through, I create a subtask and then the other issue, and I then attempt to place the subtask reference in the Single Issue Picker on the other issue. I get the following error when I attempt to do so:

customfield_13400:Issue: TIS-1028 does not fit filter query: 

customfield_13400 is the Single Issue Picker field, and TI-1028 is the subtask that I just created. I have no JQL on the Single Issue Picker field, so any issue should be a valid value.

I can go in through the UI and set the field as I wish (e.g. I can go into that issue right now and set the field to TIS-1028, and it saves just fine).

I can also update the issue through the script console using the same code that I use in my post function.

I can also hard-code a previously attempted (and failed) subtask reference in the code in the post function.

It appears that the subtask is not fully stored or indexed, thus preventing me from referencing it in this field. I CAN, however, immediately reference it and create a link to/from it.

I've got an open ticket with Atlassian, but I'm not really getting anywhere with it, so I wanted to see if anyone in the Community has encountered a similar situation.

Thanks!

2 answers

0 votes
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2019

I tried several different orders on the post functions and also tried manually indexing, all to no avail. I finally threw in the towel and changed from a Single Issue Picker to a text field. Not as tight an integration as I would like, but it works. The field is programmatically set and never edited, so there is no concern about integrity.

-Payne

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2019

What is the order of execution for all your post-functions?
Are you using the built-in create-subtask post function?
It would be helpful to understand how all your pieces come together to come up with some ideas.

A bit of assumption here... but I would guess that if you have the issue key available during the post function... then the new issue has been stored. But perhaps it hasn't been indexed yet.

So maybe adding a manual indexing of the subtask before attempting to set the issue picker value might help.

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 23, 2024

Having the same issue myself, @Payne  did you find a resolution to your issue?

 

the script we are using is below, added as the last post function on an Approve Transition.
We also get the same error, the newly created Issue does not match the filter for the Issue Picker.  The Issue Picker field does not have a filter applied.
We attempted to comment the line out that updates the issue picker field which then gives us another scenario, with the source issue status. Not for this thread.
The below works when run explicitly in the console against an issue having the Approved status.
Have raised a request with The Adaptavist Group Support/ScriptRunner for Jira Data Center/SRJSUP-36138

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
import org.apache.log4j.Level

Logger jiraLog = Logger.getLogger(this as String)
jiraLog.setLevel(Level.DEBUG)

    Issue sourceIssue = issue
    sourceIssue.refresh().reindex()

   
Issue destinationIssue

    ApplicationUser issueApprover // Added these, so we can reference it throughout the Class Methods
    String approvalDate
    AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager()

    UserAccounts    userAccounts = new UserAccounts()
    jiraLog.debug('Source Issue: ' + sourceIssue.getKey())
    //List<Approval>
    def approvals = sourceIssue.getApprovals()
    jiraLog.debug(approvals[0].getClass())
 
    approvals.each { approval ->
        if (approval.getDecision()) {
            jiraLog.info("Approval Decision: ${approval.getDecision().get().decision}")
            jiraLog.info("Approved Date UTC: ${approval.getDecision().get().completedDate}")
            //approvalDate = approval.getDecision().get().completedDate.toString() // Set Approval, As String?
            approval.getApprovers().each{ approver ->
                approver.getApproverDecision()
                if (approver.getApproverDecision()) {
                    if (approver.getApproverDecision().get().name() == 'APPROVED') {
                        jiraLog.info("Approved By User: " + approver.approverUser.getDisplayName())
                        issueApprover = approver.approverUser   // Set Issue Approver
                    }
                } else {
                    //jiraLog.info("No Response From: " + approver.approverUser.getName())
                }
            }
        } else { jiraLog.debug('Approval Still Pending') }
    }
    //Create OPS Issue
    destinationIssue = Issues.create('OPS','Service Request' ) {
        setSummary(sourceIssue.getSummary() + ' Approved By: ' + issueApprover.getDisplayName() )
        setReporter(sourceIssue.getReporter())
        setLabels('Ops-Access-Request')
        setRequestType('Request')

        //Check Source Issue for installations
        if (sourceIssue.getCustomFieldValue('Installations - Unknown')){
            setCustomFieldValue('Installations - Unknown',sourceIssue.getCustomFieldValue('Installations - Unknown'))
        }else if (sourceIssue.getCustomFieldValue('Installations')){
            setCustomFieldValue('Installations'){
                sourceIssue.getCustomFieldValue("Installations").each { intObject->
                    add(intObject.getObjectKey())
                }
            }
        }
        setCustomFieldValue('Handed Over From', sourceIssue.getKey())
    }

    jiraLog.debug('Handed Over To Issue: ' + destinationIssue.getKey() )
  attachmentManager.copyAttachments(sourceIssue,Users.getLoggedInUser(),destinationIssue.getKey())

    destinationIssue.refresh().reindex()
    sourceIssue.refresh().reindex()
    sourceIssue.refresh().transition('Handover'){
        transitionOptions { skipConditions() }
        //setCustomFieldValue('Handed Over To', destinationIssue.refresh().getKey())
    }.addComment('Issue Has Been Handed Over, Issue ' + destinationIssue.getKey() + ' Has been raised in the ' +  destinationIssue.getProjectObject().key + ' Project.'){internal()}




Suggest an answer

Log in or Sign up to answer