How to get new project key on Clone Plus plugin with Behaviours

JacksonC January 17, 2020

Hello, 

When doing a Clone to another project (using the Clone Plus Plugin), are you able to get the project key of the new project being cloned into?

I've been searching and testing all day.

issueContext.projectObject.key  - Always returns the key of the issue being cloned from.

I tried variations of getFieldByName and getFieldByID with project/projects/Project/Projects and it always returns nulls.

I'm trying to use the Behaviours Plugin to hide fields depending on the selected project.

Thanks in advance.

3 answers

1 accepted

0 votes
Answer accepted
Matthew Clark
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 27, 2020

Hi Jackson,

In general with behaviours, we only have access to the information within the current screen and also from the context that is provided by Jira.

The methods we sent you in the support case here will give you access to the project selected in the default Jira Project Field when on the Create screen, and if you are on the edit screen it gives access to the underlying issue's project.

From the community post, it seems you are trying to access something from another plugin. We do not have any built-in methods that detect the variables this other plugin uses to tell the user the "New project Name".

If this plugin "Clone plus" stores the new project name/key in a field that we can access on-screen, then you should be able to use the default behaviours methods for getting field values by getting the FormField object and the calling getValue(). I have however tried to do this here to verify and although the field is on the screen and has the id "issue-create-project-name", its value is always null for both initialiser scripts and field server-side scripts. This means we cannot get the value of this field.

I have also looked at the context variables and they only contain the data of the current project and not the target project specified by your Clone Pluss addon.

The good news:

I had a deeper look into all possible variables on screen and it does appear there is one variable that stores the Project ID of the target project.
It is however only available when the form has been fully loaded which means you have to put the behaviour on a field and NOT an initialiser.

The summary field is usually on all these screens so you could attach the script to the summary field, then whenever the clone+ link is clicked it should trigger the behaviour script.

Here is an example you can use to get at the Clone Plus target project Object using the project Id pid. Refer to the atlassian-jira.log to see the log output results.

 

Regards

Matthew

JacksonC January 29, 2020

This is great thank you! It worked well.

0 votes
Amir Katz (Outseer)
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 19, 2020

You mention Behaviour. I assume you mean the feature that comes with ScriptRunner.

If that's the case, you cannot do that - the Behaviour groovy code is translated into Javascript code that is injected into the web page. Cloning runs in the background and does not display any user-editable screen.

A possible solution would be to create a listener on Issue Created event and in it check if the issue has an issue link of type Cloners. It's not a guarantee, but I think it's a good start.

JacksonC January 19, 2020

That is correct, I am using ScriptRunner.

I believe Behaviours should let you some how get the "Project" field on the form.

That would solve it really easy. 

Amir Katz (Outseer)
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 19, 2020

There are two ways to get the project key in a Behaviour script:

def projectObj = underlyingIssue?.getProjectObject() 
if (projectObj) {  
projectKey = projectObj.key   // Plan A
else {  
projectObj = getIssueContext().getProjectObject()  
projectKey = projectObj?.getKey()
  //plan B
}
JacksonC January 19, 2020

Yes, I know that. I've tried both of those. Those don't seem to be getting what is displayed on the form. 

You know how on the page at the very top it has the field "Project".

If you do a clone from one project to another, everything I've tried so far always gets the value of the original project being cloned from, I  can't seem to be getting the value of the second project.

For example,

If I'm in project ABC and I want to clone the issue into XYZ, in the behaviours I want to get the value of XYZ which is displayed at the very top of the page.

Amir Katz (Outseer)
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 19, 2020

So the next step is to open a support ticket with Adaptavist. You're paying big $$ for ScriptRunner, so you're entitled...

JacksonC January 19, 2020

Thank you, I have opened one.

I'll provide what I find out here from them.

I really appreciate your help.

0 votes
Stephen Wright _Elabor8_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 18, 2020

Hi @JacksonC

Have you tried the app's support pages, where you can view their wiki or contact them directly? As it's a vendor they will have a more direct answer :)

Ste

JacksonC January 19, 2020

Thank you for your help. I will open a support ticket.

Stephen Wright _Elabor8_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2020

Awesome - let us know if you locate the right solution :)

Ste

Suggest an answer

Log in or Sign up to answer