Project and Issue Type Behaviours

You may have the same behaviour mapped to multiple projects or issue types, and you need to do different things depending on the project or issue type selected.

Your initial instinct may be to add the Issue Type or Project field to the behaviour. However this won’t work in the way that you expect.

Behaviours are mapped to project and/or issue type combinations. So if you change the issue type, the current behaviours are thrown away and new ones are retrieved for the new project/issue type combination, therefore you cannot listen for project and issue type changes.

To explain by way of counter-example. If you changed the issue type to one that had no behaviours, it wouldn’t make sense for the existing behaviour to continue running.

The correct way to handle switching on issue type or project name/key is using an initializer:

groovy
if (issueContext.issueType.name == "Bug") { ... } if (issueContext.projectObject.key == "FOO") { ... }

Initializers will run whenever the project or issue type changes, so you can make fields readonly, required etc. there.