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 initialiser:

if (issueContext.issueType.name == "Bug") {
    ...
}

if (issueContext.projectObject.key == "FOO") {
    ...
}

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

For how-to questions please ask on Atlassian Answers where there is a very active community. Adaptavist staff are also likely to respond there.

Ask a question about ScriptRunner for JIRA, for for Bitbucket Server, or for Confluence.