Versioner sammenlignet

Nøgle

  • Linjen blev tilføjet.
  • Denne linje blev fjernet.
  • Formatering blev ændret.

...

Advarsel

Do notice the Issue List is rather long and with some old problems still open

Info

The plugin has been purchased by Adaptavist in 2015 and is from version 4 Paid Product.

 

Indholdsfortegnelse

Change Task Type

This actually gets hold on a clone and changes the "Task Type" Custom Field to "Clone", whereas on the Master it is still "Master"

Kodeblok
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
 
def componentManager = ComponentManager.instance
def optionsManager = componentManager.getComponentInstanceOfType(OptionsManager.class)
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Task Type'}
def fieldConfig = cf.getRelevantConfig(issue)
def optionClone = optionsManager.getOptions(fieldConfig).find {it.value == "Clone"}
issue.setCustomFieldValue(cf, optionClone)

 

Setting Issue values after "Create Subtask" 

In This sample "transientVars" refers to the parent values

...

Kodeblok
issue.assignee == transientVars["issue"].assignee;
issue.setAssignee(null);
issue.setDescription("A new Description");
issue.setSummary("Unit Test - " + transientVars["issue"].key);

Getting a Custom Field Value (String)

Kodeblok
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
CustomField UseCustomer = customFieldManager.getCustomFieldObject(10600);

System.out.println("Custom field value: " + issue.getCustomFieldValue(UseCustomer));

 

Setting a Custom Field Value (String)

Taken the value fetched above:

...

This does not work for all field types (like labels).

Assigning a user

Kodeblok
String userName="pho"
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserObject(userName)
issue.setAssignee(user)

//Update the issue - may not be nessesary
ComponentManager.getInstance().getIssueManager().updateIssue(ComponentManager.getInstance().jiraAuthenticationContext?.user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
ComponentManager.getInstance().getIndexManager().reIndex(issue);

...

Kodeblok
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.Permissions
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.util.ImportUtils
 
//Examples, 8 is my subtask issue type id. Will be different for others
updateAssignee("PRJ-1485", "user1")
 
//Method to do all the work
def updateAssignee(parentId, userName) {
def issue = ComponentManager.getInstance().getIssueManager().getIssueObject(parentId)
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserObject(userName)
issue.setAssignee(user)
//Update the issue
ComponentManager.getInstance().getIssueManager().updateIssue(ComponentManager.getInstance().jiraAuthenticationContext?.user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
ComponentManager.getInstance().getIndexManager().reIndex(issue);
}

 

Remove and Set labels

Kodeblok
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.label.LabelManager
import org.springframework.util.StringUtils
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

labelManager = ComponentManager.getComponentInstanceOfType(LabelManager.class)
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();


CustomField UseCustomer = customFieldManager.getCustomFieldObject(10600);
CustomField Customer = customFieldManager.getCustomFieldObject(10900);


labelManager.removeLabelsForCustomField(10900)


Set labelSet = new HashSet();
labelSet.add(issue.getCustomFieldValue(UseCustomer));


def componentManager = ComponentManager.getInstance()
def authContext = componentManager.getJiraAuthenticationContext()
def user = authContext.getUser()


// issue.getCustomFieldValue(UseCustomer)
// Does not work - the "labelSet" is not a valid set - https://answers.atlassian.com/questions/332748/set-labels-in-jira
labelManager.setLabels(user, issue.id,labelSet, false,false)

 

Transist Linked Issues

This is very nice, for "auto" progressing linked issues. (Idea and source from this)

...

Tip

The

Kodeblok
workflowTransitionUtil.setIssue(issueLink.getDestinationObject());

should be

Kodeblok
workflowTransitionUtil.setIssue(issueLink.getSourceObject());

Going "the other way". There is also an getInwardLinks(issue.id) collection.

 

Get CurrentUser

Kodeblok
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
User = ComponentManager.getInstance().getJiraAuthenticationContext().getUser().getName();

Send Custom Mail

Some standard JIRA Field can be accessed very direct, other must be throught the 

...

Kodeblok
<% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Mail Body")) %>
<br><br>
Best Regards,
<br><br>
GService Desk
<br>
<a href="http://sd.mydomain.dk">Service Desk</a>
<br>
You cant reply to this email.

 

Making Fields Required 

This script is a sample from a Validation Function

Kodeblok
// This script makes a requirement: if the Custom Field "OprStatusShow" is set to public, Incident Start and Resolved must be set.

import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

//Project "Support" Id = 10130
if (issue.getProjectObject().getId() == 10130) {

ComponentManager componentManager = ComponentManager.getInstance();
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();
CustomField IncidentResolvedField = customFieldManager.getCustomFieldObject("customfield_12224");
CustomField IncidentStartField = customFieldManager.getCustomFieldObject("customfield_10091");
CustomField OprStatusShowField = customFieldManager.getCustomFieldObject("customfield_11820");


String IncidentResolved = (String)issue.getCustomFieldValue(IncidentResolvedField);
String IncidentStart = (String)issue.getCustomFieldValue(IncidentStartField);
String OprStatusShow = (String)issue.getCustomFieldValue(OprStatusShowField);

if (OprStatusShow == "Yes") {

	if (IncidentStart == null || IncidentResolved == null) {
		InvalidInputException e= new InvalidInputException();
		e.addError("Incident Start And Incident Resolved must not be empty");
	 	throw e;
		}
	}
}

 

Scripted Fields

A "neat" but raw idea for a scripted field: https://answers.atlassian.com/questions/191893

 

Links

https://jamieechlin.atlassian.net/wiki/display/GRV/Post+Functions

...