Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,464,508
Community Members
 
Community Events
176
Community Groups

Scriptrunner - Values written to a ticket via groovy script don't seem to persist.

Hello,

I have a strange issue with a script I wrote to take some data from somewhere, and add it to the summary and description field of a new issue on creation. (Note, the api URL I'm using in the example below is just for testing - just an easy API to get data back from)

 

I'm guessing my problem is with the "issue.store()" method. Maybe I'm missing a parameter, or maybe I shouldn't even be using this method (it shows as deprecated in IntelliJ IDE). I'm just not sure what the "right" way is to store the new summary and description.

 

What happens is very strange. If I create the new ticket while I'm on the "Open Issues" page for my project, it all appears to work. If I refresh, that new ticket shows up, but it has the junk data that I typed in manually to the summary field. If I click once on that new ticket to view all the details about it, the summary gets updated at that point to have the data that my script is placing in it.

If I refresh - it all happens again - starts off with initial summary data - click on it, then it gets the real data.

 

 

 

Here's the script - it's running based on a Script listener, that triggers on issue creation and issue update:

import com.onresolve.scriptrunner.runner.util.UserMessageUtil

import com.atlassian.jira.ComponentManagerimport com.atlassian.jira.issue.Issue;

import com.atlassian.jira.issue.IssueManager;

import com.atlassian.jira.issue.MutableIssue;

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.issue.fields.CustomField;


//variables

def heatTicketFieldId = "customfield_10404"

def apiUrl = "https://api.macvendors.com"

 

//set issue variableIssue issue = issue;


//Get heat ticket number from custom field
def issueManager = ComponentAccessor.getIssueManager()

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def heatTicketField = customFieldManager.getCustomFieldObject(heatTicketFieldId)

def heatTicketNumber = issue.getCustomFieldValue(heatTicketField)

 


//if heat ticket field has a value, look it up, if not, return nothing.

if(heatTicketNumber == null){

return

}

else{

def completeUrl = apiUrl + "/" + heatTicketNumber

def connection = completeUrl.toURL().openConnection()

connection.setRequestMethod("GET")

connection.doOutput = false

connection.connect()

def ticketContent = connection.content.text


def newSummary = "HEAT Ticket:" + heatTicketNumber

def newDescription = "Ticket content: " + ticketContent

issue.setDescription(newDescription)

issue.setSummary(newSummary)

issue.store()


UserMessageUtil.success("Created JIRA ticket " + issue.key + " from HEAT ticket " + heatTicketNumber)}

 

 

 

1 answer

Hey Dan,

in all of our problems, where an issue would not show updated values we used the IssueManager function

  • updateIssue

    Issue updateIssue(ApplicationUser user,
                      MutableIssue issue,
                      EventDispatchOption eventDispatchOption,
                      boolean sendMail)
    This method will store the provided issue to the JIRA datastore.

    The issue will be saved and re-indexed unless EventDispatchOption.DO_NOT_DISPATCH is specified. This method performs no permission checks.

    This method should be used if you want to exert more control over what happens when JIRA updates an issue. This method will allow you to specify if an event is dispatched and if so which event is dispatched, see EventDispatchOption. This method also allows you to specify if email notifications should be send to notify users of the update.

    Parameters:
    user - who is performing the operation
    issue - the issue to update
    eventDispatchOption - specifies if an event should be sent and if so which should be sent.
    sendMail - if true mail notifications will be sent, otherwise mail notifications will be suppressed.
    Returns:
    the updated issue.
    Throws:
    IssueFieldsCharacterLimitExceededException - when issue fields exceed the jira character limit
    Since:
    v4.0

(Function Reference from https://docs.atlassian.com/software/jira/docs/api/7.8.0/com/atlassian/jira/issue/IssueManager.html)

Thanks for the info. I got it working in a similar way, but I used IssueService instead.

 

 

IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
//Setting Issue Input Parameters
issueInputParameters.setDescription(newDescription)
issueInputParameters.setSummary(newSummary)

IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(currentUser, issue.getId(), issueInputParameters);

if(updateValidationResult.isValid()) {
IssueResult updateResult = issueService.update(currentUser, updateValidationResult);

}else{

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events