Forums

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

Projectrack and Scriptrunner

Maahshid Vaziri
Contributor
August 15, 2022

Hi

I use the Projectrack for project tracking in Jira, In this plugin, there is a field called project status, can you guide me on how to get the value of this field with the Script Runner?

Footnote: I have attached a part of the code related to the API between these two programs in the form of a photo

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.deiser.jira.profields.api.project.Project
import com.deiser.jira.profields.api.field
import com.deiser.jira.profields.api.field.status
import com.deiser.jira.profields.api.value.ValueService


def Project_Id = project?.id
def Project_Key = Project.getKey()
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey(Project_Key)

log.warn("Project: $Project_Key : $Project_Id")

@WithPlugin("com.deiser.jira.profields")
Project_Status = getValue(com.atlassian.jira.project.Project project,StatusField field)

if(Project_Status == "Closed")
    {
    String permissionScheme = "Closed"
    ComponentAccessor.getPermissionSchemeManager().removeSchemesFromProject(project)
    ComponentAccessor.getPermissionSchemeManager().addSchemeToProject(project, ComponentAccessor.getPermissionSchemeManager().getSchemeObject(permissionScheme))
    }

1.JPG

2.JPG

1 answer

1 accepted

2 votes
Answer accepted
Florian Bonniec
Community Champion
August 16, 2022

Hi @Maahshid Vaziri 

 

What the name of the field you want to get ?

Have you try something like this ?

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.project.Project

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.fields.CustomField

import com.deiser.jira.profields.api.project.Project

import com.deiser.jira.profields.api.field

import com.deiser.jira.profields.api.field.status

import com.deiser.jira.profields.api.value.ValueService

def Project_Id = project?.id

def Project_Key = Project.getKey()

def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey(Project_Key)

log.warn("Project: $Project_Key : $Project_Id")

@WithPlugin("com.deiser.jira.profields")

@PluginModule

ValueService valueService

@PluginModule

FieldService fieldService

def statusField = fieldService.getWithIgnoreCase(<REPLACEWITHFIELDNAME>)

log.error(statusField)

if(statusField.size() == 1){

    def project_Status = valueService.getValue(project,statusField.first())

    if(project_Status.getText() == "Closed")

        {

        String permissionScheme = "Closed"

        ComponentAccessor.getPermissionSchemeManager().removeSchemesFromProject(project)

        ComponentAccessor.getPermissionSchemeManager().addSchemeToProject(project, ComponentAccessor.getPermissionSchemeManager().getSchemeObject(permissionScheme))

        }

}
Maahshid Vaziri
Contributor
August 16, 2022

Hi @Florian Bonniec 

many thanks for your help.

First, regarding your question, I must say that the name of the field is "project status". I want to use this script for automation, which at the beginning of the automation is supposed to check if the project status field changes, this script will be executed (that is, it has nothing to do with the issue and works directly with the project). How do I get the project key in the script? Because this automation is supposed to be applied to all projects and find each one that changed, but because it is an automatic process, I have to say in the script that I saw that it was the project that changed, give me the project key :) And finally, thanks for the code , yes it works :*)

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25 europe, atlassian event, barcelona 2025, jira, confluence, atlassian intelligence, rovo, ai-powered collaboration, developer tools, agile teams, digital transformation, teamwork solutions, atlassian conference, product announcements

🌆 Team '25 Europe registration is now open!

Join the largest European gathering of the Atlassian Community and reimagine what’s possible when great teams and transformative technology come together. Plus, grab your Super Fan ticket now and save over €1,000 on your pass before prices rise on 3 June.

Register now
AUG Leaders

Atlassian Community Events