Forums

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

Project Permission Scheme

Maahshid Vaziri
Contributor
August 17, 2022

Hello, I have written a script file on Automation that if one of the fields of the project (Project Status) is updated, then the permission scheme of the project will also change. But it does not work :(

Could you Help me?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.item.status.StatusItemService
import com.deiser.jira.profields.api.field.status.StatusField
import com.deiser.jira.profields.api.value.ValueService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.deiser.jira.profields")
Project project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("FBSW3120");
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
def statusItemService = ComponentAccessor.getOSGiComponentInstanceOfType(StatusItemService.class)
def statusField = (StatusField) fieldService.get(1)

if(statusField == "IN PRODUCTION")
    {
    String permissionScheme = "In-Production Projects Permission Scheme"
    ComponentAccessor.getPermissionSchemeManager().removeSchemesFromProject(project)
    ComponentAccessor.getPermissionSchemeManager().addSchemeToProject(project,    ComponentAccessor.getPermissionSchemeManager().getSchemeObject(permissionScheme))
    }

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
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.
August 17, 2022

I think you've got two problems here.

The obvious one is that your code, if it were to work, would trash your project.   The "remove schemes" call removes all schemes.

The less obvious one is that admin actions such as changing schemes are protected, limited to those who have admin rights.  Your script is not being run by an admin.

I'd also want to question why you're doing this - a reconfiguration of a project is not something you would usually want to automate.

Maahshid Vaziri
Contributor
August 17, 2022

Dear @Nic Brough -Adaptavist- 

Thanks for your reply, Ops I didn't know the "delete plans" call deletes all plans, what should I do? Is there an alternative class?

And for your last question, we have many projects whose status has been changed by the project manager, not Jira Admin, we want to automatically track and update all projects based on status.

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