Forums

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

In behavior project-field and issuetype-field returning null on create screen

OToole
Contributor
March 21, 2019

I need to check some fields based on user roles in a behavior.  It works perfectly everywhere except the create screen because in create screen I can't use the underlyingIssue to get project roles.   I can get it working if I hard code the project id.  Project proj = projectManager.getProjectByCurrentKey("IT");    But I would rather it be dynamic.  If they ever copy or rename the project I don't want to have to go in and update all of the behaviors.

So I added a field behavior script on a drop down.  Using the Create button on the top of the page and select the project and issue type.  Then change my dropdown field to trigger script that contains:

log.debug "context " + getContextIssueId()
log.debug "behavior context " + getBehaviourContextId()
log.debug "proj " + getFieldById("project-field")
log.debug "issue type " + getFieldById("issuetype-field")

And get all equal to null in my logs.

019-03-21 08:47:23,815 http-nio-8080-exec-9 DEBUG tamara.otoole 527x19443x1 pex58r 10.55.141.219 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] context null
2019-03-21 08:47:23,815 http-nio-8080-exec-9 DEBUG tamara.otoole 527x19443x1 pex58r 10.55.141.219 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] behavior context null
2019-03-21 08:47:23,815 http-nio-8080-exec-9 DEBUG tamara.otoole 527x19443x1 pex58r 10.55.141.219 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] proj Form field ID: project-field, value: null
2019-03-21 08:47:23,815 http-nio-8080-exec-9 DEBUG tamara.otoole 527x19443x1 pex58r 10.55.141.219 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] issue type Form field ID: issuetype-field, value: null

 I also tried adding

getFieldById("project-field").setReadOnly(true)

This does grey out the field, so it appears to work,  but I can still use the dropdown and change the value!  

 

1 answer

1 accepted

0 votes
Answer accepted
Mark Markov
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.
March 21, 2019

Hello @OToole 

To get chosen project or issue type on create screen, you need IssueContext object and behaviours have method for that, try it

log.debug("Project: ${getIssueContext().getProjectObject().getKey()}")
log.debug("Issue type: ${getIssueContext().getIssueType().getName()}")
OToole
Contributor
March 26, 2019

I really thought I had tried printing the issueContext also and it was null,  but I double checked and this worked!

Thanks

Suggest an answer

Log in or Sign up to answer