How to Restrict a workflow transition based on component lead(in post functions,conditions etc)

syamasundararao ratti January 6, 2019

Hi Team,

I want to restrict a workflow transition based on component lead. Could you please help me on this.

Scenario: when user creates an issue they will select Component related to their issue. As we know, each component in project will have it's component lead.The same component lead should be able to make a transition in workflow. Could you please help me on how to implement this. Thank you.

 

Regards,

Syam

2 answers

1 vote
Deleted user January 6, 2019

Hi @syamasundararao ratti,

 

Natively this is not possible to transition an issue based on the component lead. You need a Power Scripts addon. This will gives you a validator option.

Here is the tutorial for the same.

https://confluence.cprime.io/display/TR/Validator+for+component+lead#app-switcher

 

Thanks,

Sravya

1 vote
Alexey Matveev
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.
January 6, 2019

Hello,

You would need an add-on for it.

For example, you could use the Power Scripts add-on:

https://marketplace.atlassian.com/apps/43318/power-scripts-jira-script-automation?hosting=cloud&tab=overview

You could write a condition with a code like this:

for (string comp in components) {
if (getProjectComponentLead(project, comp) == currentUser()) {
return true;
}
}
return false;
Graham Twine _Slm_ November 27, 2019

@Alexey Matveev  I am using Scriptrunner but it looks like the following ALWAYS returns true

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

return issue.components.find { c ->
c.componentLead.key == currentUser.key
}


 I have also tried saving the search to a found user and comparing that with the current user. No joy :(

 

UPDATE:

Using the script console I discovered I was wrong,  this returns null but the transition is permitted. This is a workflow condition so I would expect null or false to prevent the transition. Very confusing indeed.

Graham Twine _Slm_ November 27, 2019

mmm Ok i have resolved this...

 

/**
* Only a Component Lead can approve a request
*
*/
import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def leads = issue.components.collect {
it.lead
}

return currentUser.key in leads

Suggest an answer

Log in or Sign up to answer