Forums

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

Custom JQL function: membersOfProjectRole

Yves Martin
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 Champions.
February 1, 2018

  Hello

I am looking for a way to test "assignee in membersOfProjectRole(PROJECTKEY)" as standard "membersOf" is restricted to JIRA groups.

I have found a pending request: https://jira.atlassian.com/browse/JRASERVER-21711

And some example code at https://mraddon.blog/2016/02/17/jql-custom-function-userinrole-with-groovy-for-jira/ and https://mraddon.blog/2017/01/03/lastcommentcontains-jql-function-for-jira-7-2-scriptrunner/

May you please provide updated code of this function for JIRA 7.6/7.7 ?

@Adaptavist SuppWould it be possible for this JQL function to be included in plugin itself ?

Thank you in advance for your help

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
PD Sheehan
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 Champions.
March 24, 2021

Can you include some screenshots of your configurations?

Are you positive that the last field in the form is correctly populated: Issue Link Type / Direction

If you leave that blank, no links are created between the original and cloned issue.

If that's correct but you still don't get links, make sure the "run as" user has permission to create links.

The logs area in the execution history will only show logs that you manually output using log.info("some text") either in the condition or in the additional action blocks.

Michiel V_
Contributor
March 24, 2021

Hi Peter-Dave,

I am positive that the last field was filled out. I have also checked but there aren't even any issues being created in the target project, so there is nothing to be linked.

I am Jira Admin of our entire server at the moment (as of recently so I am not very experienced yet) and I should have all the necessary rights to move/clone/create issues. When I navigate to the relevant projects I am able to perform these actions manually so that confirms it.

Some screenshots and extra info below.

 

Clone_And_Link_Listener_1.png

 

Clone_And_Link_Listener_2.png

 

The two screenshots above show the configuration of the listener. There was a bunch of codes in the "Conditions" and "Additional issue actions" fields earlier but I scrapped all of it to be sure that these are not causing the issues.

Target_Issue_Type.png

 

Event_Trigger.png

 

PD Sheehan
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 Champions.
March 24, 2021

I've only used this configuration directly in a workflow post function.
Since you are only firing on a single project and workflow event, that might be a better place for it.

But I would try to add the following to condition (just to be sure)

log.info "Evaluating condition for Move to Pending Event: $event.issue"
true

That might give you some clues.

What I'm wondering right now is if this type of built-in script knows how to handle custom events (as yours clearly is). I've worked mostly with system events.

Or, the custom event is not loaded with an issue object and the built-in script doesn't have anything to act on.

You can troubleshoot that by creating a separate custom event and outputting to the log some of the objects bound to the custom event.

But if the built-in script can't work on the custom event, your best bet will be to move the config to the workflow postfunction.

Michiel V_
Contributor
March 25, 2021

Alright so I've been trying a few more things.

Yesterday evening we had to reset our server because of reasons. Since the server reset, the Listener does seem to work but only if i leave the "Condition" field blank.

When I add my desired condition (which is a component check) it does not run.

log.info "Evaluating condition for Move to Pending Event: $event.issue"
issue.components == 'Jira Service Desk'

Note that I added the log.info line as you suggested, but this does not seem to provide any log info at all. As shown on the screenshot below;

logs_with_log_code_line.png

However, when I trigger the Listener when the Condition field is blank (not even the log.info line is in there), the logs do return something. Note that the Listener is working in this case even though this log message shows up.

2021-03-25 18:28:00,290 WARN [servicedesk.ServiceDeskUtils]: Failed to retrieve service desk for KLVV: The Service Desk you are trying to view does not exist.

 

This leads me to believe that something is wrong with my (very simple) condition.

issue.components == 'Jira Service Desk'

The compared value matches the Component label set on the ticket which I used for testing perfectly. Is something else wrong with this Conditional check?

JiraServiceDesk_Component.png

PD Sheehan
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 Champions.
March 25, 2021

That's mysterious...

 

Regarding component condition... try

issue.components.any{it.name == 'Jira Service Desk'}

//or

issue.components.every{it.name == 'Jira Service Desk'}

That's because issue.components should return a list of ProjectCopmonent objects. you want to compare the name of those objects.

Michiel V_
Contributor
March 26, 2021

Hi Peter-Dave,

I tried

issue.components.any{it.name == 'Jira Service Desk'}

and now it works like a charm! Thank you very much! 

TAGS
AUG Leaders

Atlassian Community Events