Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,028
Community Members
 
Community Events
168
Community Groups

Projectrack and Scriptrunner

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

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))

        }

}

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