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, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events