Forums

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

Retrieving getContextIssueId() or getBehaviorContextId() when project is changed

Richard Kiefer March 26, 2018

Hi,

we are implementing a Create Constrained Issue web item, and we like to prefill it. We also like the user to be able to change the project in which the contrained issue is created.

Now, working with getContextIssueId() and getBehaviorContextId() works fine in a behavior's intitializer method for opening the create screen. However, these methods return null when the user changes the project in that screen and the behavior is evaluated again. Hence, the prefilling statements fail once the project is changed, leaving the user with empty fields.

This can be easily checked with the following initializer method:

def contextIssue = getContextIssueId()
def behaviorcontext = getBehaviourContextId()

getFieldById("summary").setFormValue("issue context ${contextIssue} and behavior context ${behaviorcontext}")

Is this a bug? Is there another way of storing the issue-context and behavior-context across project-switches, e.g. with transient variables?

We are using ScriptRunner 5.2.2.

Thanks a lot!

Richard

2 answers

1 accepted

1 vote
Answer accepted
Martin Öhlinger
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 18, 2018 edited

Hi Richard,

I recently ran into the same problem an solved it using a cache.

 

Initialiser Method:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.cache.Cache
import com.atlassian.cache.CacheManager

def cacheManager = ComponentAccessor.getComponent(CacheManager.class);

if (getBehaviourContextId() == "create-story") {
def contextIssue = issueManager.getIssueObject(getContextIssueId())

Cache<String, String> cache = cacheManager.getCache("behaviour-context");
cache.put("contextId", getBehaviourContextId());
cache.put("contextIssueId", Long.toString(getContextIssueId()));

/* TODO your logic */
}

 

Fields "Project" (or in my case "IssueType") Method

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.cache.Cache
import com.atlassian.cache.CacheManager

def cacheManager = ComponentAccessor.getComponent(CacheManager.class);

Cache<String, String> cache = cacheManager.getCache("behaviour-context");
def contextId = cache.get("contextId");

if (contextId == "create-story") {
String contextIssueId = cache.get("contextIssueId");
def contextIssue = issueManager.getIssueObject(Long.parseLong(contextIssueId))

/* TODO your logic */

/* clear data from cache */
cache.remove("contextIssueId");
cache.remove("contextId");
}

 

Hope this helps!

 

Best regards
Martin 

Richard Kiefer June 19, 2018

Hi Martin, thank you so much for sharing your approach! Good to know about the caching facilities. See also my answer pointing to a bug report.

Martin Öhlinger
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 19, 2018

Hi Richard, thank you for the link to the bug report.

I want to point out that my solution is not very good as you can only change the "project" or "issuetype" once. After this change the cache will be empty again.

I am still trying to figure out a better solution.

1 vote
Richard Kiefer June 19, 2018 edited

Adaptavist considers this a bug, see https://productsupport.adaptavist.com/browse/SRJIRA-2747

Hopefully, it will be fixed soon. Leave your feedback there to demonstrate your interest in the issue.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events