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)}
Hey Dan,
in all of our problems, where an issue would not show updated values we used the IssueManager function
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.
user
- who is performing the operationissue
- the issue to updateeventDispatchOption
- 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.IssueFieldsCharacterLimitExceededException
- when issue fields exceed the jira character limit(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{
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.