Link with context issue

Veera rdy April 18, 2018

Hello,
I'm implementing a create issue button "Sub-Story" using script fragment. I'm using behaviors to default the summary, components and create a link between the new issue and the context issue.

All this is working good as long as we do not change the project on the screen. If we select the project to a different one, the behaviors is not working: i.e the components and issue link field is going back to empty.

We would like to have the same capability even if the project is changed i.e the components and link issue field should be defaulted from the context issue.

Please advice.

Thanks.

1 answer

0 votes
JohnsonHoward
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.
April 19, 2018

Hi Veera,

What is the configuration for your behaviour like? Is it mapped to a specific project?

Please can you show me the code you are using and the details of the configuration of the behaviour. 

Thanks

Johnson

Veera rdy April 19, 2018

Hi Johnson,

Please see the behavior below.

import com.atlassian.jira.issue.IssueManager;
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager


def issueManager = ComponentAccessor.getIssueManager()
def CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

getFieldById("issuelinks-linktype").setFormValue("Original")

if (getBehaviourContextId() == "CreateSubStory") {
def contextIssue = issueManager.getIssueObject(getContextIssueId())
getFieldById("issuelinks-linktype").setFormValue("Original").setReadOnly(true)
getFieldById("project-field").setFormValue(contextIssue.getProjectObject().name)
getFieldById("issuetype-field").setReadOnly(true)
getFieldById("summary").setFormValue(contextIssue.summary)
getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(true).setHidden(true)
}

Thanks.

JohnsonHoward
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.
April 20, 2018

Hi Veera,

Have you added this as an initialiser or is it mapped to a field?

I think I will need to see the configuration screen in order to understand this issue fully.

I cam see that you set the project field to match the context issue, therefore I assume this is not an initialiser as this code will change the project back to the context issue project even if you change it to a different one.

Also, is the issue type configured for both projects (the original and the one you change it to) ?

Thanks

Johnson 

Veera rdy April 26, 2018

Hi @JohnsonHoward,

The behavior is mapped as an initialiser.

I cam see that you set the project field to match the context issue, therefore I assume this is not an initialiser as this code will change the project back to the context issue project even if you change it to a different one.---- This doesn't happen. I'm able to change the project.

Also, is the issue type configured for both projects (the original and the one you change it to) ?-YES

Please let me know if you need any more info

Thanks.

JohnsonHoward
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.
April 27, 2018

Hi Veera rdy,

Have you tried checking the logs for more information. Also, logging out information from the behaviour scripts. 

Like this:

 log.info("CONEXT" + getBehaviourContextId().toString())

If you put this before the if statement you will be able to see if the context you are looking for is correct. 

There is a ScriptRunner built-in script called 'View Server Log File' , go on this and choose 'atlassian-jira-log' from the drop down, then click your script fragment and change the project type, then run the log file builtin script to see what gets output. 

Ann Kristin January 24, 2020

Did you find any solution to this? 

I am experiencing the same problem. The initialiser works as expected, but as soon as we change Project or Issuetype, it seems like the form "forgets" everything about the context issue and just becomes a fresh Create Screen dialog. (Except if you have anything in Summary, but that is a different story.) 

If I try to use Server Side script, it works as long as Project and Issuetype is not changed, but as soon as any of these are changed, the Create Issue dialog knows nothing about the context issue anymore...  

I also tried to copy the context issue key to a temporary textfield, but all fields (except Summary) are cleared as soon as Project or Issue Type is changed, so no luck. 

Not sure how to solve this without creating a button for each project, which is a no go really.... 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events