### Compile and Install Vendors API Example Plugin Source: https://docs.adaptavist.com/sr4js/latest/integrations/vendors-api/vendors-api-example-plugin This section details the process of compiling the Vendors API Example Plugin using Maven and installing the resulting JAR file into a Jira instance. It also includes troubleshooting steps involving frontend build processes. ```Shell atlas-mvn package ``` ```Shell npm install npm run build ``` -------------------------------- ### New Example Script for Web Panel Fragment Source: https://docs.adaptavist.com/sr4js/latest/release-notes/feature-release-summary A new example script is available specifically for creating a web panel fragment. This provides a practical starting point for developers building web panels with ScriptRunner. ```Groovy /* * A new example script is available for when you create a web panel fragment. */ // Example of a Groovy script for a Jira web panel fragment // def issue = ComponentAccessor.getIssue(request.getParameter('issueId')) // def html = "

Web Panel Content for Issue: ${issue.key}

" // return html ``` -------------------------------- ### Example Behaviour XML Retrieval URL (ScriptRunner 6.0+) Source: https://docs.adaptavist.com/sr4js/latest/get-help/get-help-with-behaviours An example of a REST API URL used to fetch the XML configuration for a behaviour with ID '1' in ScriptRunner for Jira Data Center 6.0+. ```bash /plugins/servlet/scriptrunner/admin/behaviours/edit/1 ``` -------------------------------- ### ScriptRunner: Fast-track Transition Listener Example Source: https://docs.adaptavist.com/sr4js/latest/features/listeners/listeners-tutorial This example outlines setting up a ScriptRunner listener to fast-track an issue transition. It triggers on 'Issue Commented' events for high-priority issues and transitions the issue to 'Start Progress', optionally skipping permissions. ```Groovy // Example condition for high priority issues issue.priority.name == '_Major_' // Action: Start Progress (configured in listener settings) // Skip Permissions: true (configured in listener settings) ``` -------------------------------- ### Get Atlassian SDK Version Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-code/set-up-a-dev-environment This command retrieves the version of the Atlassian SDK installed, which is useful for locating the Maven binaries. The output provides the 'ATLAS Maven Home' directory, essential for configuring IntelliJ's Maven settings. ```bash atlas-version ``` -------------------------------- ### HAPI Examples for Jira Scripts Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x New examples demonstrating the integration of HAPI within Jira scripts. These examples are designed to be explored and customized for specific Jira instances. ```Groovy /* * Example script demonstrating HAPI usage for Jira. * This script can be customized for your Jira instance. */ // Example: Accessing Assets/Insight properties using HAPI def insightService = ComponentAccessor.getComponent(com.onresolve.jira.groovy.jsw.services.InsightService) def assetData = insightService.getAssetByItsIdentifier("your-asset-key") println "Asset Data: ${assetData}" // Example: Working with issue properties using HAPI def issueService = ComponentAccessor.getComponent(com.onresolve.jira.groovy.jsw.services.IssueService) def issueProperty = issueService.getIssueProperty(issue.id, "your-property-key") println "Issue Property: ${issueProperty}" // Example: Working with user properties using HAPI def userService = ComponentAccessor.getComponent(com.onresolve.jira.groovy.jsw.services.UserService) def userProperty = userService.getUserProperty(currentUser.name, "your-user-property-key") println "User Property: ${userProperty}" ``` -------------------------------- ### User Guides for Jira Service Desk and SmartDraw Integration Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-5-x Provides best practices and examples for using ScriptRunner with Jira Service Desk and SmartDraw. Demonstrates automating tasks like creating RCA documents, cloning issues, and generating backlog diagrams. ```Groovy // Example: Automatically create a Root Cause Analysis document // This is a conceptual example, actual code would depend on specific requirements // def issue = ... // Get the current issue // def rcaContent = "Root Cause Analysis for issue: ${issue.key}" // // Logic to create a document or update a field ``` ```Groovy // Example: Clone and link an issue from a Jira Service Desk ticket // def issue = ... // Get the JSD ticket // def clonedIssue = issueService.cloneIssue(issue) // linkManager.createLink(issue, clonedIssue, linkType, ...) ``` ```Groovy // Example: Email all watchers of issues linked to a development ticket // def developmentTicket = ... // def linkedIssues = issueLinkManager.getLinkedIssues(developmentTicket) // linkedIssues.each { linkedIssue -> // linkedIssue.getWatchers().each { watcher -> // // Send email to watcher // } // } ``` ```Groovy // Example: Automatically generate a diagram of your backlog using SmartDraw Object Notation (SDON) // This would involve fetching backlog issues and formatting them into SDON // def backlogIssues = searchService.search(...) // def sdonData = buildSdonFromIssues(backlogIssues) // // Logic to send sdonData to SmartDraw API or generate a file ``` -------------------------------- ### Basic Spock Test Structure Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-and-run-tests A fundamental Spock test specification demonstrating the setup, when, and then blocks for writing and asserting script behavior. This example uses Groovy and the Spock framework. ```groovy import spock.lang.Specification class MyVeryOwnScriptSpec extends Specification { def "test that my script does what I say it does"() { setup: "create any test data I need (projects, issues, etc.)" when: "I invoke run my script" //write code that makes your script run here then: "my script makes the changes I expect" true //Each line is an assertion 1 == 1 //Anything that returns true will let the test pass "a" == "b" //Anything that returns false will cause the test to fail } } ``` -------------------------------- ### ScriptRunner Jira: Example script to search and link issues Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x Provides an example script that allows searching for issues using a JQL query and linking them to another issue. This script is accessible through the Example Scripts modal. ```Jira SRJIRA-7181 - Example Script: Search and Link Issues ``` -------------------------------- ### New Example Scripts Modal and Editor Redesign Source: https://docs.adaptavist.com/sr4js/latest/release-notes/feature-release-summary A new modal for example scripts has been added, and the code editor has been redesigned for improved user-friendliness. This aims to make it easier for users to find and utilize script examples. ```Groovy /* * New Example Scripts modal * The code editor has been redesigned so it's even more user-friendly. */ // The new modal and editor are UI features. Scripting interaction might involve: // - Accessing the example scripts via a new API if available. // - Using the redesigned editor for writing custom scripts. // Example of accessing a script fragment (hypothetical): // def scriptFragmentManager = ComponentAccessor.getComponent(ScriptFragmentManager) // def exampleScript = scriptFragmentManager.getExampleScript('my-script-name') ``` -------------------------------- ### New Web Panel Example Script Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x This snippet provides an example of a new web panel script, as documented in version 8.18.0. It illustrates how to create a web panel using ScriptRunner. ```Groovy // Example script for a new web panel // This is a placeholder for a web panel script return "
This is a web panel
" ``` -------------------------------- ### Example Script for Web Panel Fragment Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x A new example script has been made available for creating web panel fragments. This script serves as a simple illustration, demonstrating how to implement a colored banner within a web panel. ```Groovy // Example Groovy script for a colored banner in a web panel import com.atlassian.jira.component.ComponentAccessor def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() // Simple HTML with inline style for color return """

Welcome, ${user.displayName}!

This is a colored banner example.

""" ``` -------------------------------- ### Start Atlassian Applications with `atlas-mvn` Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-code/set-up-a-dev-environment Commands to start Jira, Confluence, Bitbucket, and Bamboo instances locally using `atlas-mvn` for debugging. These commands initiate a local instance accessible at `http://localhost:8080/`. ```Shell cd atlas-mvn jira:debug atlas-mvn confluence:debug atlas-mvn bitbucket:debug atlas-mvn bamboo:debug ``` -------------------------------- ### YAML Configuration for ScriptRunner Plugin Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-code/create-a-script-plugin This snippet shows an example of a `scriptrunner.yaml` file used to configure extension points within a ScriptRunner script plugin. The file details the configuration for an extension point, which is automatically applied upon plugin installation. ```yaml scriptrunner: listeners: -. class: com.adaptavist.scriptrunner.example.MyListener event: jira.issue.created rest: -. path: /my-rest-endpoint methods: GET: -. class: com.adaptavist.scriptrunner.example.MyRestEndpoint ``` -------------------------------- ### Automation for Jira Actions Example Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x This snippet demonstrates the new Automation for Jira actions and triggers (Beta) introduced in version 8.12.0. It shows a basic example of an automation action. ```Groovy // Example of an Automation for Jira action // This is a placeholder for an automation action log.info "Automation action executed" ``` -------------------------------- ### New Example Script for Web Panel Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x Introduced in version 8.18.0, this example script demonstrates how to create a web panel using ScriptRunner for Jira. It provides a basic structure for web panel development. ```Groovy import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.plugin.web.model.WebPanel import com.atlassian.jira.plugin.web.model.WebPanelBuilder // Example script for a web panel def userManager = ComponentAccessor.getUserManager() def currentUser = userManager.getUserByKey(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getName()) def webPanelBuilder = new WebPanelBuilder() webPanelBuilder.setTemplate("templates/webpanel.vm") // Assuming a template file named webpanel.vm webPanelBuilder.addParameter("user", currentUser) def webPanel = webPanelBuilder.build() return webPanel ``` -------------------------------- ### Enable Plugin Upload in Jira Data Center Source: https://docs.adaptavist.com/sr4js/latest/get-started/installation This section explains how to re-enable the plugin upload functionality in Jira Data Center for specific versions where it is disabled by default. It highlights the Jira versions affected and the action required to restore this feature. ```text The plugin upload from the UI (_upload app_ link) is disabled by default on Jira versions equal to or higher than 9.4.17, 9.12.4, 9.14.0, re-enable plugin upload in Jira Data Center. ``` -------------------------------- ### Groovy Script Example Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-code/script-roots An example of a Groovy script that logs a message and calls a static method from another class. This demonstrates basic script execution within ScriptRunner. ```groovy import util.demo.Bollo log.debug ("Hello from the script") Bollo.sayHello() ``` -------------------------------- ### ScriptRunner Jira Compatibility and Library Updates Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-9-x This entry highlights general Jira compatibility and a library update where example scripts have been moved to ScriptRunner HQ. This suggests a change in how example scripts are accessed or managed. ```text Jira compatibility ``` ```text Library update: Example scripts have moved to ScriptRunner HQ ``` -------------------------------- ### ScriptRunner JQL AI Example Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x This snippet provides an example of the new ScriptRunner JQL AI feature, documented in version 8.22.0. It illustrates how to use JQL with AI capabilities. ```Groovy // Example of ScriptRunner JQL AI usage // This is a placeholder for actual JQL AI query "issueFunction not in linkedIssuesOf(\"JIRA-123\")" ``` -------------------------------- ### Groovy Utility Class Example Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-code/script-roots An example of a Groovy class designed to be used by other scripts. It includes a static method that returns a string, demonstrating how to create reusable utility classes. ```groovy package util.demo public class Bollo { public static String sayHello() { "hello sailor!!!" } } ``` -------------------------------- ### Dynamic Forms: optionsGenerator Example Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x This example demonstrates the usage of `optionsGenerator` in dynamic forms, allowing for the programmatic generation of options for form fields. This is part of the dynamic forms update. ```Groovy def optionsGenerator = { def options = [] for (i in 1..5) { options.add([value: "Option ${i}", label: "Option ${i}"]) } return options } // In a form definition: // field.setOptions(optionsGenerator()) ``` -------------------------------- ### Show Multiple Component Leads Source: https://docs.adaptavist.com/sr4js/latest/features/script-fields/custom-script-field/custom-script-field-examples This example demonstrates how to display the lead users for all components assigned to a Jira issue. It iterates through the components and concatenates their lead information. ```Groovy // Example: Show leads for all components def componentLeads = issue.getComponents().collect { it.getLeadUserName() }.findAll { it != null } if (componentLeads.isEmpty()) { return "No component leads found." } else { return "Component Leads: ${componentLeads.join(', ')}" ``` -------------------------------- ### YAML Configuration File Example Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-code/store-all-environment-specific-variables An example of a YAML file used to store environment-specific variables. This file can be customized to include any key-value pairs required for your application configuration. ```YAML Approvals: customfield_12345 Long Custom Field Name: customfield_56789 ``` -------------------------------- ### Finding ScriptRunner SEN and Version in Jira Source: https://docs.adaptavist.com/sr4js/latest/get-help This guide explains how to locate your ScriptRunner license SEN and installed version within the Jira administration interface. It involves navigating to the 'Manage Apps' section and expanding the ScriptRunner details. ```Jira Administration 1. Navigate to**Manage Apps** _Jira Administration Menu_. 2. Click**Manage Apps** _Atlassian Marketplace_. 3. Locate ScriptRunner and expand the information. The**Installed Version****License SEN** ``` -------------------------------- ### ScriptRunner Jira Listeners Tutorial Source: https://docs.adaptavist.com/sr4js/latest/training/course-introduction-to-scriptrunner-for-jira-data-center-server/1-3-video-using-listeners-in-scriptrunner-for-jira-data-center-server This snippet refers to a written tutorial for understanding and implementing listeners in ScriptRunner for Jira Data Center/Server. It is a guide for users who prefer text-based instructions. ```English For a written tutorial on listeners, see the Listeners Tutorial page. ``` -------------------------------- ### Replace ComponentManager with ComponentAccessor Source: https://docs.adaptavist.com/sr4js/latest/get-started/update-scriptrunner/compatibility-with-jira Shows how to replace the deprecated ComponentManager usage with the new ComponentAccessor for accessing Jira managers and services. This includes examples for getting CommentManager and ProjectService. ```groovy import com.atlassian.jira.ComponentManager import com.atlassian.jira.bc.project.ProjectService def commentManager = ComponentManager.instance.commentManager // or def commentManager = ComponentManager.getInstance().getCommentManager() // or def commentManager = ComponentManager.getCommentManager() // getting some other type of service def projectService = ComponentManager.getInstance().getComponentInstanceOfType(ProjectService) ``` ```groovy import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.bc.project.ProjectService def commentManager = ComponentAccessor.commentManager def projectService = ComponentAccessor.getComponent(ProjectService) ``` -------------------------------- ### Create Software Project Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-and-run-tests/test-workflow-functions Creates a new software project with a specified name, key, lead, and template. It validates the project creation request using projectService and then creates the project. Dependencies include ProjectTypeKey, AssigneeTypes, and projectService. ```Groovy private Project createTestSoftwareProject() { def creationData = new ProjectCreationData.Builder().with { withName("Test Project") withKey("TEST") withLead(currentUser) withAssigneeType(AssigneeTypes.PROJECT_LEAD) withType(new ProjectTypeKey('software')) withProjectTemplateKey("com.pyxis.greenhopper.jira:basic-software-development-template") } def result = projectService.validateCreateProject(currentUser, creationData.build()) assert !result.errorCollection.hasAnyErrors() projectService.createProject(result) } ``` -------------------------------- ### Groovy REST Endpoint Example Source: https://docs.adaptavist.com/sr4js/latest/features/rest-endpoints A basic Groovy script demonstrating how to define a REST endpoint. It handles GET requests, specifies allowed groups, and returns a JSON response. ```Groovy import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate import groovy.json.JsonBuilder import groovy.transform.BaseScript import javax.ws.rs.core.MultivaluedMap import javax.ws.rs.core.Response @BaseScript CustomEndpointDelegate delegate doSomething( httpMethod: "GET", groups: ["jira-administrators"] ) { MultivaluedMap queryParams, String body -> return Response.ok(new JsonBuilder([abc: 42]).toString()).build() } ``` -------------------------------- ### Introduction to Atlassian Java API Video Source: https://docs.adaptavist.com/sr4js/latest/training/course-introduction-to-scripting-in-scriptrunner-for-jira-data-center-server/2-3-video-introduction-to-atlassian-java-api This section refers to a video that introduces the Atlassian Java API, likely for use with ScriptRunner for Jira. No direct code is provided here, but it points to a learning resource. ```text 2.3 Video: Introduction to Atlassian Java API ``` -------------------------------- ### Groovy Snippets for Custom Script Fields Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x Provides example Groovy code snippets to assist developers in creating and updating custom script fields within ScriptRunner for Jira. These snippets serve as templates or starting points for custom field logic. ```Groovy // Example snippet for a custom script field import com.onresolve.jira.groovy.user.Field // Accessing issue data def issue = Field.getIssue() // Example: Setting a field value // Field.setFieldValue("customfield_10001", "New Value") // Example: Returning a value for display // return "Calculated Value" ``` -------------------------------- ### Clone ScriptRunner Samples Project Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-code/set-up-a-dev-environment This command clones the ScriptRunner samples project from the provided Bitbucket URL. This project contains script plugins for ScriptRunner Suite and is used to connect various development tools. ```git https://bitbucket.org/adaptavistlabs/scriptrunner-samples ``` -------------------------------- ### Groovy Basics for ScriptRunner Source: https://docs.adaptavist.com/sr4js/latest/training/course-introduction-to-scripting-in-scriptrunner-for-jira-data-center-server This video covers the fundamental concepts of the Groovy scripting language as applied to ScriptRunner for Jira Data Center/Server. It is essential for users looking to leverage ScriptRunner's automation capabilities. ```Groovy def message = "Hello, ScriptRunner!" println message ``` -------------------------------- ### Get Custom Field Value and Set Description using Behaviours Source: https://docs.adaptavist.com/sr4js/latest/integrations/vendors-api/vendors-api-example-plugin This Groovy script demonstrates how to retrieve the value from the 'Vendors API' custom field and use it to set the 'Description' field's value when the 'Summary' field is modified. It uses getFormValue and setFormValue methods. ```Groovy def fieldValue = getFieldByName('Vendors API').getFormValue() getFieldByName('Description').setFormValue(fieldValue) ``` -------------------------------- ### Get Portfolio Child Issues with portfolioChildrenOf Source: https://docs.adaptavist.com/sr4js/latest/features/jql-functions/included-jql-functions/portfolio Retrieves child issues within a portfolio or roadmap hierarchy that match a given subquery. This function does not bridge gaps between certain issue types like Epic to Story. It requires Advanced Roadmaps for Jira to be installed and a reindex to be performed. ```JQL portfolioChildrenOf(Subquery) ``` ```JQL issueFunction in portfolioChildrenOf("status = 'To Do'") and issuetype = Initiative ``` ```JQL issueFunction in portfolioChildrenOf("status = 'To Do'") ``` ```JQL filter = "Children of Themes" or issueFunction in issuesInEpics('filter = "Children of Themes"') ``` ```JQL issueFunction not in portfolioChildrenOf("issuetype = Theme") and issuetype = Initiative ``` -------------------------------- ### ScriptRunner Behaviours Examples for Jira Source: https://docs.adaptavist.com/sr4js/latest/features/behaviours/behaviours-examples This section lists various examples of ScriptRunner Behaviours for Jira Data Center. These examples demonstrate how to customize Jira fields and implement specific logic, such as setting field requirements, modifying descriptions, and controlling field visibility. ```Jira Field-Level Permissions Field Required Modify Field Descriptions Operations on Tabs Project and Issue Type Behaviours Require Comment For Action Restricting Comment Visibility Restricting Issue Types Restricting Priority and Resolution Scripted Conditions Select List Conversions Select Lists with Other Setting a Default Description Setting Field Defaults Sub-task Default Field The Linked Issues Field Using a Server-side Validator to set the Fix Versions Required ``` -------------------------------- ### Create a New User Source: https://docs.adaptavist.com/sr4js/latest/hapi/work-with-users Provides examples for creating new users in Jira using ScriptRunner. The basic creation includes username, email, and display name. Advanced creation allows setting passwords, directory IDs, and application access. ```Groovy Users.create('jdoe', 'jdoe@example.com', 'Jane Doe') ``` ```Groovy import com.atlassian.jira.application.ApplicationKeys Users.create('jdoe', 'jdoe@example.com', 'Jane Doe') { password = 'secret' directoryId = 10_001 withApplicationAccess(ApplicationKeys.SERVICE_DESK, ApplicationKeys.SOFTWARE) } ``` -------------------------------- ### Query Issues by Start Date with ScriptRunner Source: https://docs.adaptavist.com/sr4js/latest/features/jql-functions/included-jql-functions/versions The `startDate` function enables querying issues based on their associated version's start date. For instance, `fixVersion in startDate("after 14d")` finds issues in versions that start more than two weeks from now. ```JQL fixVersion in startDate("after 14d") ``` -------------------------------- ### Introduction to Atlassian Java API Source: https://docs.adaptavist.com/sr4js/latest/training/course-introduction-to-scripting-in-scriptrunner-for-jira-data-center-server This video introduces the Atlassian Java API, a key component for creating advanced automations and customizations within Jira using ScriptRunner. Understanding this API is crucial for extending Jira's functionality. ```Java import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue // Get the current issue Issue issue = ComponentAccessor.getIssueManager().getIssueObject("PROJ-123") // Get the issue manager def issueManager = ComponentAccessor.getIssueManager() // Example: Get issue summary String summary = issue.getSummary() log.info("Issue Summary: " + summary) ``` -------------------------------- ### ScriptRunner Jira: Example script to set field value from user property Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x Provides an example script for Scripted Fields that allows setting a field's value based on a user property. This script can be accessed via the Example Scripts modal. ```Jira SRJIRA-7280 - Example script (Scripted Fields): Set Field Value From User Property ``` -------------------------------- ### ScriptRunner Jira: Example script to set field value from user property using Behaviours Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x Introduces an example script for Behaviours that automatically sets a custom field value based on the assignee's email. This script can be found in the Example Scripts modal. ```Jira SRJIRA-7182 - Example script (Behaviour): Set Field Value From User Property ``` -------------------------------- ### Smart Completion with Opt+Shift+Space on Mac Fix Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-6-x Resolves an issue where smart completion did not work as expected when using Opt+Shift+Space on macOS. -------------------------------- ### Find Issues by Version Start Date Source: https://docs.adaptavist.com/sr4js/latest/features/jql-functions/included-jql-functions Filters issues based on the start date of their associated versions. This function is related to `fixVersion`. ```JQL startDate ``` -------------------------------- ### Get Changed Field ID Source: https://docs.adaptavist.com/sr4js/latest/features/behaviours/api-quick-reference Gets the ID of the field to which the current script is attached. ```groovy getFieldById(getFieldChanged()) ``` -------------------------------- ### Get Workflow for Project Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-and-run-tests/test-workflow-functions Retrieves the JiraWorkflow object for a given project by getting its workflow name and then fetching the workflow from the workflowManager. Dependencies include getProjectWorkflowName and workflowManager. ```Groovy private JiraWorkflow getWorkflowForProject(Project project) { def workflowName = getProjectWorkflowName(project) workflowManager.getWorkflow(workflowName) } ``` -------------------------------- ### Access ScriptRunner via Quick Search Source: https://docs.adaptavist.com/sr4js/latest/get-started/navigation This snippet describes how to use the quick search functionality to navigate to ScriptRunner. It includes keyboard shortcuts and search terms. ```text 1. Press the keyboard shortcut `gg`. 2. Type `ScriptRunner` in the search dialog. 3. Press `Enter` to navigate to ScriptRunner. ``` -------------------------------- ### New HAPI Code Helper Example Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x This snippet showcases a new HAPI code helper introduced in version 8.8.0. It demonstrates how to utilize the helper for ScriptRunner functionalities. ```Groovy // Example of a new HAPI code helper // This is a placeholder for actual code demonstration println "HAPI helper example executed." ``` -------------------------------- ### Making REST GET Calls with HTTPBuilder in Groovy Source: https://docs.adaptavist.com/sr4js/latest/release-notes/breaking-changes/groovy-4-breaking-change-for-grab-annotations This code snippet demonstrates how to make a GET REST call using the HTTPBuilder library, which is included with ScriptRunner. It shows how to instantiate a REST client and perform a GET request to a specified URL. ```groovy import groovyx.net.http.RESTClient def client = new RESTClient('https://jsonplaceholder.typicode.com') def resp = client.get( path: '/todos/1' ) resp['data'] ``` -------------------------------- ### Groovy Script Listener Example Source: https://docs.adaptavist.com/sr4js/latest/features/listeners/listeners-tutorial This snippet demonstrates a basic Groovy script that can be used to create a custom listener in ScriptRunner for Jira. It outlines the structure for listening to a specific Jira event and executing an action. ```Groovy // Example of a custom listener script in Groovy // This script would be configured within ScriptRunner to listen for a specific Jira event import com.atlassian.jira.event.issue.IssueEvent import com.atlassian.jira.event.issue.IssueEventListener class MyCustomIssueListener implements IssueEventListener { @Override void handle(IssueEvent event) { // Logic to execute when the event occurs log.info("Event occurred: ${event.getEventType().getName()} on issue: ${event.getIssue().getKey()}") // Example: If issue is reopened, add a comment if (event.getEventType().getName() == "Issue reopened") { // Code to add a comment or perform other actions log.info("Issue ${event.getIssue().getKey()} was reopened.") } } @Override boolean isEnabled() { // Return true if the listener is enabled return true } } ``` -------------------------------- ### Add Snippet to Fragments Script Examples Modal Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x This entry refers to the addition of a snippet within the Fragments Script Examples Modal, likely intended to provide a readily available code example for users creating script fragments. The exact code snippet is not provided but is part of a UI enhancement. ```Groovy // Conceptual representation of adding a snippet to a modal. // The actual implementation would involve UI framework code. // Example of a modal structure (simplified): // modal.addSection({ // title: 'Fragment Example' // content: new GroovyCodeDisplay(code: ''' // // Your example script here // ''') // }) ``` -------------------------------- ### Basic Groovy Script Example Source: https://docs.adaptavist.com/sr4js/latest/features/script-console A simple Groovy script example that logs debug messages. This script can be executed using the Script Console or remotely. ```groovy script.groovy log.debug ("hello") log.debug ("sailor") ``` -------------------------------- ### Search Scripts with Operating System Tools Source: https://docs.adaptavist.com/sr4js/latest/get-help/frequently-asked-questions/search-and-edit-scripts-faqs This snippet explains how to search ScriptRunner scripts effectively by recommending the use of script files. It suggests leveraging operating system file search tools or an IDE for efficient searching across multiple scripts. Using script files also enables version control for better script management. ```text If you need to frequently search all your scripts, we suggest you change from using inline scripts to using script files instead. Using script files, you can use the operating systems file search tools, or an IDE, to search all your scripts easily. If you use script files, you can also take advantage of version control, so you have better management of changes to your scripts. ``` -------------------------------- ### ScriptRunner: Remove Unused Screens Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x Provides an example script to remove unused screens from your Jira instance. This script can be accessed via the Example Scripts modal. ```Groovy // Example script to remove unused screens // Access this script via the Example Scripts modal in ScriptRunner // SRJIRA-7101 ``` -------------------------------- ### Create Jira Project Using a Template Source: https://docs.adaptavist.com/sr4js/latest/hapi/work-with-projects Creates a new Jira project using a specified project template key, along with the project key and name. The project lead is set to 'admin' by default in this example. ```Groovy Projects.create("TIS", "Teams in Space") { projectLead = 'admin' projectTemplateKey = "com.pyxis.greenhopper.jira:basic-software-development-template" } ``` -------------------------------- ### Example JQL for Issue Archiving Source: https://docs.adaptavist.com/sr4js/latest/features/jobs/built-in-jobs/issue-archiving-job-data-center An example of a JQL query to select issues for archiving. This query targets issues in a specific project that have the status 'Closed'. ```JQL project = "YourProjectKey" AND status = "Closed" ``` -------------------------------- ### Create Jira Project with Default Values Source: https://docs.adaptavist.com/sr4js/latest/hapi/work-with-projects Creates a new Jira project with a specified key and name, using default values for other project settings. This is the simplest way to create a project. ```Groovy Projects.create("TIS", "Teams in Space") ``` -------------------------------- ### Simplify Scripts with HAPI - ComponentAccessor Example Source: https://docs.adaptavist.com/sr4js/latest/hapi/simplify-current-scripts-with-hapi Demonstrates how the presence of ComponentAccessor in a script might indicate it can be simplified using HAPI. HAPI's architecture often reduces the need for direct component access. ```Groovy ComponentAccessor ``` -------------------------------- ### Custom Script Field Snippet Example Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x This snippet demonstrates the availability of snippets for custom script fields, as introduced in version 8.3.0. It shows a basic example of a script snippet. ```Groovy // Example snippet for a custom script field // This is a placeholder for a custom script field snippet return "Custom script field output" ``` -------------------------------- ### Include Additional Atlassian Applications in pom.xml Source: https://docs.adaptavist.com/sr4js/latest/best-practices/write-code/set-up-a-dev-environment This XML configuration demonstrates how to include additional Atlassian application features, such as Jira Software or Jira Service Desk, in a Maven project's pom.xml. It is done within the `` tag, specifying the `applicationKey` and version for each required application. ```XML ``` -------------------------------- ### New Custom Script Field Example Source: https://docs.adaptavist.com/sr4js/latest/release-notes/release-8-x As of version 8.3.0, snippets are available for custom script fields. This example demonstrates how to create a custom field that executes Groovy code. ```Groovy import com.onresolve.scriptrunner.runner.custom.CustomType import com.onresolve.scriptrunner.runner.custom.CustomTypeDescriptor // Example of a custom script field class MyCustomScriptField extends CustomType { @Override CustomTypeDescriptor getDescriptor() { return new CustomTypeDescriptor("My Custom Script Field", "Calculates a value based on script") } @Override Object run(Map context) { // Logic to calculate the custom field value def issue = context.get("issue") def customFieldValue = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10001")) if (customFieldValue != null) { return customFieldValue.toString().toUpperCase() } else { return "N/A" } } } ```