Preview:
// 1. importing Classes and Packages

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager


def component = ComponentAccessor.getComponent()

// 2. Applying your Import

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager

def projectManager = ComponentAccessor.getComponent(ProjectManager)

// 3. We now have an object that instantiates (is an instance of) the ProjectManager class, and we can move on to exploring its methods.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager

def projectManager = ComponentAccessor.getComponent(ProjectManager)

return projectManager.getProjectObjects()

/*There’s nothing between the brackets, so we know that it’s not expecting input of any kind. By running this code in the ScriptRunner Console directly, the data returned should be the project keys of every project in your jira instance.*/
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter