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
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.