Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Help with scriptrunner in jira cloud

Edimara June 2, 2023

I have a script in Jira Data Center, but the context is different and I'm having trouble adapting the code to script runner cloud

 

 

How can I declare this in cloud?

 

def category = issue.getProjectObject().getProjectCategoryObject();
    def project= issue.getProjectObject().getName()
if (!category)
{
// my code

1 answer

0 votes
Bobby Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 2, 2023

Hi @Edimara , 

 

The code you need is this: 

def projectKey = issue.fields.project.id

def project = get("/rest/api/3/project/$projectKey")
.asObject(Map)
.body

def projectCategoryName = project.projectCategory?.name

logger.info(projectCategoryName)

if(project.projectCategory == null){
// code to execute if there is no project category
}



Just to clear up the logic, if you have the issue, we can see from the GET Issue API documentation that you have the project object, which includes the ID. 

Once we have the ID, we need to get the project itself, so do the GET Project API call. This is the equivalent of ".getProjectObject()". We can see from the GET Project API documentation that the response includes not only the Project Category, but also the additional information such as the name, so we don't need another API call and can access it directly. 

Hope this helps!


Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events