use this to get component lead -
issue.getComponentObjects().getAt(0)?.getLead()
Run transition in another issue
Epic name custom field
https://community.atlassian.com/t5/JIRA-questions/inheriting-epic-name-to-subtask/qaq-p/272228
Get class of the returned object:
log.error cfValues['DateFieldA']?.class?.name
Get Issue
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("TST-2")
Logging:
http://www.adaptavist.com/doco/display/SFJ/Set+logging+to+help+debug+your+scripts
Due Date + 14 days
issue.setDueDate(new Timestamp((new Date() + 14).time))
Date Picker CF
issue.setCustomFieldValue(cf, (new Date()).toTimestamp())
Save MutableIssue
MutableIssue mutableIssue = (MutableIssue) issue
ComponentAccessor.getIssueManager().updateIssue(mutableIssue.getCreator(), mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
groovy event listener
https://answers.atlassian.com/questions/296425/run-a-small-groovy-script-on-any-issue-change
Issue updated event
https://answers.atlassian.com/questions/223177/issue-updated-event-contents
Get value from Metadata
https://answers.atlassian.com/questions/36179103/how-to-get-metadata-in-groovy-postfunction
Set watcher in issue
Escalation service
https://jamieechlin.atlassian.net/wiki/display/GRV/Escalation+Service
Mail through gmail
https://gist.github.com/quchie/3e02c5d5df8de804e8e0
Detect field change
https://answers.atlassian.com/questions/11991592/how-to-detect-if-a-field-value-was-changed
JNDI source
https://answers.atlassian.com/questions/209645/scriptrunner-and-jndi-database-access
Decode workflow inline scripts:
decoder
https://gist.github.com/jechlin/eea390104f609c4b9b011854007db62f
Get Screens in Behavior and Hide field in selected Edit Screens
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.operation.IssueOperations
def issue = underlyingIssue
def screen = ComponentAccessor.getIssueTypeScreenSchemeManager().getFieldScreenScheme(issue).getFieldScreenSchemeItem(IssueOperations.EDIT_ISSUE_OPERATION )
if (screen.getId().toString() in ["18100", "19920", "19925"]) {
getFieldById("customfield_21952").setHidden(true)//Custom Field
}
Update date time field
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
currField.updateValue(null, issue, new ModifiedValue("", (Object) date.toTimestamp()), new DefaultIssueChangeHolder())
Get all methods for a class:
import com.onresolve.scriptrunner.canned.jira.utils.CannedScriptUtils
/**
* @function printAllMethods
* @purpose Prints an objects class name and then list the associated class functions.
*/
// Filename: printAllMethodsExample.groovy
void printAllMethods( obj ){
if( !obj ){
log.error( "Object is null\r\n" );
return;
}
if( !obj.metaClass && obj.getClass() ){
printAllMethods( obj.getClass() );
return;
}
def str = "class ${obj.getClass().name} functions:\r\n";
obj.metaClass.methods.name.unique().each{
str += it+"(); ";
}
log.error "${str}\r\n";
}
//def priorities = CannedScriptUtils.getPriorityOptions(true)
printAllMethods(CannedScriptUtils)
Fragment:
"HOW TO HIDE THE CREATE SUB-TASK FROM MORE WORKFLOW BUTTON AT PARTICULAR STATUS IN JIRA TICKET" . To execute this need "Script Runner" Add-On.
so GoTo--->Admin Settings--->Add-On's--->Left Pannel List Script Runner--->Select Script Fragements--->Add New Item and Select 'Hide system or plugin UI element ' -----> In that in Hide What option select the "com.atlassian.jira.plugin.system.issueoperations:create-subtask" ------> In Condition run this script given below
def currentStatus = issue.status.name
!(currentStatus == "Done") // instead of 'Done' put your status in which status you want to hide the Create Sub-Task
Drop all attachments in the Issue
List AttachmentI = attachmentManager.getAttachments(issue)
AttachmentI.each {attachment ->
attachmentManager.deleteAttachment(attachment)
}
Re-Index
MutableIssue newIssue = issueFactory.getIssue()
newIssue.setProjectObject(targetProjectObject)
newIssue.setIssueTypeObject(subTaskIssueType)
newIssue.setReporter(reporter)
newIssue.setSummary(summary)
newIssue.setPriorityId(priorityId)
newIssue.setCustomFieldValue(appDueDate, parentIssue.getCustomFieldValue(appDueDate))
newIssue.setComponent(parentIssue.getComponents())
newIssue.setCustomFieldValue(appSubDesc, parentIssue.getCustomFieldValue(appSubDesc))
String issueKey = ""
Map<String, Object> newIssueParams = ["issue": newIssue] as Map<String, Object>
if (true) {
Issue reallyNewIssue = issueManager.createIssueObject(reporter.name, newIssueParams)
issueKey = reallyNewIssue.getKey()
log.error "New issueKey:" + issueKey
ComponentAccessor.subTaskManager.createSubTaskIssueLink(parentIssue, reallyNewIssue, loggedInUser)
issueLinkManager.createIssueLink(reallyNewIssue.id, parentIssue.id, 10260L, 0L, reporter)
boolean isIndex = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
IssueIndexingService IssueIndexingService = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class)
IssueIndexingService.reIndex(reallyNewIssue)
ImportUtils.setIndexIssues(isIndex)
}