I want to store project ID in field - project description. Is there any way to copy project ID from project description and add this value to custom field of each issue created under this project?
Can it be done via automation rule or maybe Script Runner app? Any suggestions or maybe there is easier way to apply project ID value to each issue?
Hi @Natalia Marko and welcome,
try to add a scripted post function in creation with the following code :
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.project.Project;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
IssueManager issueManager = ComponentAccessor.getIssueManager();
Project project = issue.getProjectObject();
CustomField yourField = customFieldManager.getCustomFieldObject("CUSTOMFIELD_LONG_ID_HERE");
MutableIssue mIssue = (MutableIssue) issue;
mIssue.setCustomFieldValue(yourField, project.getDescription());
issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), mIssue, EventDispatchOption.DO_NOT_DISPATCH, false);
Obviuosly you custom field should be a text field.
Hope this helps,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.