Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,361,498
Community Members
 
Community Events
168
Community Groups

How to update issue after getting value from dialog box using script runner

Dear Experts,

 

My scenario is 

  • I have created a button on issue
  • When user click on the button "update issue", system shows a dialog box , to confirm
  • Once your said yes, then update the issue with default parameters(i am not explaining here as there so many

Till here i am done and its working.

 

I am using script runner rest end point and javascript to get the value from  if they said yes.

 I have a groovy method which is updating the field after receiving the key.

I am stuck here how to proceed further, how can i execute the groovy method inside the javascript, once user said proceed.

1 answer

1 accepted

0 votes
Answer accepted

Hi @Muhammad Ramzan 

 I have a groovy method which is updating the field after receiving the key.

Is this groovy method available as a rest endpoint?

If so, you could make an ajax call from your dialog box javascript to that rest endpoint and provide the issue key as a parameter.

 Here is a recap of scriptunner configuration you will likely need:

  1. GET rest endpoint to serve the html of the dialog2 element
  2. POST rest endpoint to receive issue key and perform actions on the issue
  3. Web Item fragment to display the button that will call GET 
  4. Web Item resource to hold the Javascript used by the dialog2 and trigger an AJAX POST action when the confirm button is clicked (optional, you could also just embed your js in #1)

@Dear @Peter-Dave Sheehan , many thanks for the solution. I found the solution and did the same as you suggested here. Its working like a champ. many thanks,

Hello, 

we have a similar challange. We are able to fill the fields back from dialog to Jira, but we struggle to make an Issue.Update Event. 

 

May your share how you solved it`?

You should not have to raise an event manually.

There are 3 ways I'm aware of for updating fields (in order of recommended preference)

  1. IssueService.update(user, validationResult, EventDispatchOption, sendMail)
    • This will generate the event specified in EventDisapatchOption
    • It will also add the change to issue history
    • It will automatically take care or re-indexing the issue
  2. IssueManager.updateIssue(user, issue, EventDisapatchOption, sendMail)
    • This will do all the same as the above except the indexing. Indexing has to be triggered manually
  3. CustomField.updateValue(fieldLayout, issue, ModifiedValue, changeHolder)
    • It's a low-level API that just changes the db value for the custom field.
    • This may or may not update the issue history. I haven't experimented with this in a while.
    • But there is certainly no event and not indexing taking place

If you use the first 2, you can specify to raise an IssueUpdated event.

we checkd out everything, won't work.

Here is our Rest EndPoint Relay:

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import javax.ws.rs.core.Response.Status
import groovy.transform.Field
import groovy.json.JsonSlurper
import static groovyx.net.http.Method.*
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response


@BaseScript CustomEndpointDelegate delegate

String issueKey = null
String BuildStatusValue = null    

BuildStatusRelay(httpMethod: "POST") {
    MultivaluedMap queryParams,
    def payload ->
        def jsonSlurper = new JsonSlurper()
        def content = jsonSlurper.parseText(payload)
        issueKey = content.key
        BuildStatusValue = content.body
        def im = ComponentAccessor.getIssueManager()
        def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
        MutableIssue issue = im.getIssueObject(issueKey)  
        def cfm = ComponentAccessor.getCustomFieldManager()
        def customField = cfm.getCustomFieldObject(24970)
        UpdateIssueRequest updateIssueRequest = UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build()

      
        customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), BuildStatusValue),new DefaultIssueChangeHolder())
        def user = ComponentAccessor.getUserManager().getUserByName("kdomschk")
        //im.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
        im.updateIssue(user, issue, UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build())
        im.updateIssue(user, issue, updateIssueRequest)
        issueIndexingService.reIndex(issue)
        //IssueService.update(user, validationResult, EventDispatchOption, sendMail)
       
    Response.ok(payload).build()
   
}

public class Data {
    String customFieldID
    String value
    String issueKey  
}

Try this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonSlurper
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

String issueKey = null
String BuildStatusValue = null

BuildStatusRelay(httpMethod: "POST") { MultivaluedMap queryParams, String payload ->
def jsonSlurper = new JsonSlurper()
def content = jsonSlurper.parseText(payload)
issueKey = content.key
BuildStatusValue = content.body
def im = ComponentAccessor.issueManager
MutableIssue issue = im.getIssueObject(issueKey)
def user = ComponentAccessor.getUserManager().getUserByName("kdomschk")
def cfm = ComponentAccessor.getCustomFieldManager()
def customField = cfm.getCustomFieldObject(24970)

issue.setCustomFieldValue(customField, BuildStatusValue)
im.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
Boolean wasIndexing = ImportUtils.indexIssues
ImportUtils.indexIssues = true
issueIndexingService.reIndex(issue)
ImportUtils.indexIssues = wasIndexing

Response.ok(payload).build()

}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Apps for Confluence you won't want to miss: RSVP for September's Appy Hours

Calling all collaborators and Confluence users! Our Appy Hours event on September 29th features 4 presenters demoing functionality to superpower Confluence. Don't miss learning about these apps i...

123 views 0 9
Read article

Atlassian Community Events