Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Adaptavist: groovy behaviour script to fill fields on creation form (from context issue)

Serj Shcherbakov May 24, 2018

Hi Guys,

My behaviour script is set values to fields on creation issue form.

I faced with problem: Assignee field is empty (unassigned) after creation.

What i missed?


My Script:

import com.onresolve.jira.groovy.user.FieldBehaviours
import static com.atlassian.jira.issue.IssueFieldConstants.*
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser

def issueManager = ComponentAccessor.getIssueManager()
def contextIssue = issueManager.getIssueObject(getContextIssueId())
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")
def linkedEpic = contextIssue.getCustomFieldValue(epicLinkCf) as Issue
def assignee = getFieldById("assignee-field")

def developer = customFieldManager.getCustomFieldObjectByName("Developer")
def user = contextIssue.getCustomFieldValue(developer) as ApplicationUser


if (getBehaviourContextId() == "link-create-blocking") {
getFieldById("project-field").setReadOnly(true)
getFieldById("issuetype-field").setReadOnly(true)
getFieldById("issuelinks-linktype").setFormValue("Linked to Testing").setReadOnly(true)
getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(true)
getFieldByName("Epic Link").setFormValue(linkedEpic.key).setReadOnly(true)
if ((user) != null)
{
assignee.setFormValue(user.displayName)setReadOnly(false)
}
}

 Snapshots:
script.jpg

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Serj Shcherbakov May 27, 2018

Hi Thanos,
Your solution does not works: now assignee field does not populate on creation form,
PFA:

new.jpg

0 votes
Thanos Batagiannis _Adaptavist_
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.
May 25, 2018

Hi Сергей,

The id of the assignee field is wrong, and since you already import the IssueFieldConstants (good practice) then 

def assignee = getFieldById(ASSIGNEE)

Regards, Thanos

TAGS
AUG Leaders

Atlassian Community Events