Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

I need to create a field with MyGroovy Edited

Hello everybody

I need to create a new field called and automate a process, which I will explain below.

1. Let him check the type of problem.
2. Check the value of the "Epic Link" field for that issue.
3. Add that value to the new created field.
4. And in case it is a subtask problem, find the value of the "Epic link" field of the parent task of that subtask and add it to the new field of that subtask ... since as you well know, that field " Epica Link "does not appear in subtasks.

I have thought with MyGroovy but I have never done it, I do not know if they could give me a hand.

Thanks in advance.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project


def customFieldManagerPackges = ComponentAccessor.getCustomFieldManager()
def cFieldLinkEpica = customFieldManagerPackges.getCustomFieldObject("customfield_10002")
def cFieldValueLinkEpica = issue.getCustomFieldValue(cFieldLinkEpica).toString()
def cFieldValue = issue.getCustomFieldValue(cFieldLinkEpica)

def cFieldEnlaceÉpicaAux = customFieldManager.getCustomFieldObjectByName("Textcustomfield_13403¨)
issue.setCustomFieldValue(cFieldEnlaceÉpicaAux, cFieldValue)

 

I get an error in the last Issue field

1 answer

I think, your problem is not related to MyGroovy, but to the Jira API.

  • There are 2 single quotes (') instead of 1 double quote (") at the end of the field name.
  • Is it really "Textcustomfield_13403" and not "customfield_13403"?
  • You named your customFieldManager customFieldManagerPackges.
  • There is no method setCustomFieldValue in com.atlassian.jira.issue.Issue. There is one in com.atlassian.jira.issue.MutableIssue, but I don't think this is what you need - see below.

I don't know if it's the best solution, but this should work for you:

  • Append imports:
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.util.IssueChangeHolder;
  • Replace the last two lines:
// customFieldManager.getCustomFieldObjectByName("Textcustomfield_13403¨)
// issue.setCustomFieldValue(cFieldEnlaceÉpicaAux, cFieldValue)
customFieldManager.getCustomFieldObjectsByName("customfield_13403")[0];
Object oldValue = issue.getCustomFieldValue(cFieldEnlaceÉpicaAux);
ModifiedValue modifiedValue = new ModifiedValue(oldValue, cFieldValue);
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
cFieldEnlaceÉpicaAux.updateValue(null, issue, modifiedValue, changeHolder);

Hope that helps.

Hello,

When performing the indicated steps, it gives me this error that I attach.

I must clarify that I have changed the name of the new custom field ... that's why the internal value is 13501 and not 13403

1.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Why everyone using Jira must be GDPR-compliant

Did you know that penalties up to 4 % of the yearly company turnover are possible in case of GDPR violations? GDPR regulations are currently mainly relevant for companies in the EU, but countries lik...

64 views 1 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you