Skip to content

Instantly share code, notes, and snippets.

View jechlin-adaptavist's full-sized avatar

Jamie Echlin jechlin-adaptavist

View GitHub Profile
// check the project key here is the same as the project key in the sync script
// and check the custom field ID is that of your assets custom field. Single picker is assumed
let assetsIdMap = new Project("JRA").properties.KVP_List;
issue.attachments.some(attachment =>
issue.customfield_10312.length ?
attachment.filename == assetsIdMap[issue.customfield_10312[0].objectId] + '.png' :
false
)
import java.util.stream.StreamSupport
def apiToken = API_TOKEN // Create a "Script Variable" for your api token with the name API_TOKEN. Create one at https://id.atlassian.com/manage-profile/security/api-tokens
def aqlQuery = 'objectType = Host' // AQL query - use the same query for the dropdown
def projectKey = 'JRA' // Project that we store the map of asset IDs and names on - any will do but use the one associated with this business process
def workspaceId = 'eaf39d78-2ea5-4a88-ad4f-35feb122f0c7' // Workspace ID - for assets - get it from https://<your-site>.atlassian.net/rest/servicedeskapi/assets/workspace
def search = { ->
def iterator = new Iterator<List<Map>>() {
private boolean hasMoreResults = true
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.servicedesk.api.ServiceDeskService
import com.atlassian.servicedesk.api.organization.CustomerOrganization
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.util.paging.SimplePagedRequest
import com.atlassian.upm.api.license.entity.Organization
import com.onresolve.scriptrunner.parameters.annotation.ProjectPicker
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
package com.onresolve.jira.groovy.jql
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.jql.query.LuceneQueryBuilder
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.MessageSet
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
@jechlin-adaptavist
jechlin-adaptavist / CustomFieldOptionEndpoint.groovy
Last active October 14, 2021 15:21
REST API for adding/updating and sorting custom field options
// Please see https://library.adaptavist.com/entity/provides-a-rest-api-for-creating-editing-and-sorting-select-list-options
@jechlin-adaptavist
jechlin-adaptavist / CreateUser.groovy
Created April 30, 2021 06:12
Creating users via a workflow function
package examples.champs
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
def userService = ComponentAccessor.getComponent(UserService)
def createValidationResult = UserCreationUtil.validateUserCreation(issue)
if (!createValidationResult.isValid()) {
throw new Exception('fail')
@jechlin-adaptavist
jechlin-adaptavist / ShowHide.groovy
Created April 30, 2021 06:10
Show or hide other fields according to selected options in a multi select
def selectValue = getFieldByName("MultiSelectA").getValue() as List
getFieldByName('Another Field').setHidden(!selectValue?.contains("AAA"))
getFieldByName('Yet Another Field').setHidden(!selectValue?.contains("BBB"))
@jechlin-adaptavist
jechlin-adaptavist / IssueAsXml.groovy
Created April 30, 2021 06:07
write an issue as XML to a file... it's the same XML as shown by Export > XML
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.TrustedRequest
import com.atlassian.sal.api.net.TrustedRequestFactory
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import groovyx.net.http.URIBuilder
@PluginModule
TrustedRequestFactory trustedRequestFactory