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!
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()}")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.