How to copy project description to custom field in issue?

Natalia Marko March 26, 2024

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?

 

1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 26, 2024

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events