There are 3 fields (Start Date, End Date and Summery ) which I want to copy from parent issue to sub-task.
While creating sub-task, value of these fields need to populate on create sub-task screen.
How should I write Behavior for this requirement.
I use the JMWE (Copy field value from parent issue (JMWE app)) ,it can copy fields from parent fields after created the subtask, not before.
I also use Create Subtask - JCTS ,but this plug can not copy the system fields values.
Neither of these are ideal.
Is there a better way to automatically integrate the field values of the parent task when we create a subtask?
Hi @yundong.li ,
in order to prepopulate these fields on subtask during creation you need to install and use Behaviours provided by Scriptrunner for JIRA (https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?hosting=server&tab=overview)
Hope this helps,
Fabio
Thanks for your reply!
I have install this plug,
But using it is still a bit difficult for me.
Can you provide a relevant case?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @yundong.li ,
try the following code in your behaviour :
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.user.ApplicationUser;
import java.sql.Timestamp;
IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def summary = getFieldById("summary");
def parent = getFieldById("parentIssueId");
def startDate = getFieldByName("Start Date");
def endDate = getFieldByName("End Date");
CustomField startDateCF = customFieldManager.getCustomFieldObjectByName("Start Date");
CustomField endDateCF = customFieldManager.getCustomFieldObjectByName("End Date");
if(parent!=null){
String parentId = parent.getValue();
Issue parentIssue = (Issue)issueManager.getIssueObject(Long.parseLong(parentId));
Timestamp startDateParent = (Timestamp)parentIssue.getCustomFieldValue(startDateCF);
Timestamp endDateParent = (Timestamp)parentIssue.getCustomFieldValue(endDateCF);
summary.setFormValue(parentIssue.getSummary());
startDate.setFormValue(startDateParent);
endDate.setFormValue(endDateParent);
}
Let me know,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this script is very useful for me.
when I remove the two fields of "start Date" and "End Data" , it is run good.
by the way ,I have a custom Field Department , how could I set the value?
thanks!
Looking forward to any reply from you!
there have some alarms here:
when I change to getCustomFieldObjectsByName() , there is a error display.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @yundong.li ,
alarms are related to deprecated method. It works anyway.
If you want to fix those alarms please use (use your CF id instead of 10000) :
customFieldManager.getCustomFieldObject("customfield_10000");
Start Date and End Date, in my script, are considered as Datetime fields. If they are Date
you need to set string value based on your format.
Department custom field can be setup as the others but it depends from custom field type.
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help.
It is working now.
But I find a little debug(or I donot know how to do it):
if the CustomField have two language(english and chinese) ,
when we configure it with English, and the Chinese field does not work.
For example Department - 部门, getCustomFieldObject('Department') is OK ,
bu not work for getCustomFieldObject('部门’)
Do you know how can get the jira system's language?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @yundong.li ,
as workaround please use custom field id instead of name :
customFieldManager.getCustomFieldObject("customfield_10000");
It fixs your issue.
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.