import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def issueManager = ComponentAccessor.issueManager
//Check to make sure this is the correct context for the behaviour.
if (behaviourContextId == 'CP') {
//Set the project and issuetype to be readonly so the user cannot alter these.
getFieldById('project-field').setReadOnly(true)
getFieldById('issuetype-field').setReadOnly(true)
//Find the details of the Issue from which the request to link was made
def contextIssue = issueManager.getIssueObject(contextIssueId)
//Pre-populate the Summary, issue link and issue link type.
getFieldById('summary').setFormValue("Problem created from ${contextIssue.key}").setReadOnly(false)
getFieldById('issuelinks-linktype').setFormValue('Problem for Incident').setReadOnly(true)
getFieldById('issuelinks-issues').setFormValue(contextIssue.key).setReadOnly(true)
}