Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLink;

import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.user.ApplicationUser;

CommentManager commentMgr = ComponentAccessor.getCommentManager()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue issue = im.getIssueObject("SP-5519");

return commentMgr.getComments(issue).last().body
def links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())
def output = ""
for( l in links) {
    
    //use this for Outward links
  output = output + l.issueLinkType.name + ": " +  l.getDestinationObject() + "<br/>
}

return output

8. Script to set a default value for fixVersion field for a particular issue type (Server)

Code Block
languagegroovy
def versionIdProductionMaintenance = "10214"
def actionName = "Create"

if (getActionName() != actionName) {
    return // not the initial action, so don't set default values
} 

//def issueType = getFieldById("10402").getValue().toString()
def issueType = issueContext.issueType.name

if(issueType == "Change Request") {
//get fixVersion ID
def fixVersionsFieldCR = getFieldById("fixVersions")
//set fixVersion value
def fixVersionsNewValueCR = fixVersionsFieldCR.setFormValue([versionIdProductionMaintenance])
} else {
    def fixVersionsField = getFieldById("fixVersions")
    def fixVersionsNewValue = fixVersionsField.setFormValue("")
}

Learning:

  1. Knowledge on how script-runner listener works for both cloud and server

  2. Got to understand different scenarios for Jira based on which scripts were written

  3. Basic knowledge on groovy

  4. While setting the value for multi-select system fields always set the values based on “id’s of values” and not “values itself“ in behaviors

  5. While setting the value for single select system fields we can directly give “values” instead of “id’s of values”

  6. script-runner behaviors

  7. While setting the value for single select custom field we have to give “id’s of values” only (can also be directly configured in field setting as these are custom fields)

...