Hi Community
I was trying to write a code in order to gather a custom field It would bring just one custom field. However, when there are more than one custom field of the same name, the log output will return a funky result.
Code
cFVal = customFieldManager.getCustomFieldObjectByName("Assignee Group");
Result
Warning: returning 1 of 5 custom fields named 'Assignee Group'
Now, I was trying another approach to gather the list of custom fields that are in the issue ticket. When I was looking for the list of those custom fields, it throws the whole list of customfields that I created for all projects
Code
mylist = customFieldManager.getCustomFieldObjects(parentIssue) as List<CustomField>; log.warn ("Fields ${mylist.dump()}\n\n\n\n\n\n");
Results
Fields <java.util.ArrayList@65e2db81 elementData=[ PO# (If Applicable), Added to Retro List, Alternate Rate, AssignedDeveloper, Assignee Group, Assignee Group, Assignee Group, Assignee Group, Assignee Group, Bcc, Bcc, Blocked By, Blocked By, Body, Body, Category, Category, Cc, Cc, Compliance Approved, Confirmation #1, Confirmation #2, Confirmation #3, Confirmation #4, Confirmation #5, Confirmation #6, Confirmation #7, Confirmation #8, Contact Info, Contact Info, Contains PII, Contains PII, Date Completed, Date Completed, Date Completed, Date Completed, Date of Initial Submission, Detected By, Detected By, Developer, Developer, District, Domain Name, Domain Name, Email Address, Email Address, Enter As, Epic Link, Epic/Theme, Exclusions or Incidents, Executive Summary, Executive Summary, File Hashes, File Hashes, Filenames, Filenames, First Name, Flagged, From, From, Function, Function, HR Approved, Hash Type, Hash Type, Highly Qualified, Hosting Company, Hosting Company, IP Address, IP Address, Immigration Status, Initial Notification, Initial Notification, Issue Approver, Issue Approver, Issue Creator, Issue Creator, Last Name, Lessons Learned, Lessons Learned, Location, Location, Long Term ID, Mailicious URL, Mailicious URL, Mentoring, Need Sub if Long Term Calls Out, Nitro Case ID, Nitro Case ID, Nitro Event ID, Nitro Event ID, Normalized ID, Normalized ID, Number of Days, Offer Letter Necessary, Offer Letter Received, Offer Letter Sent, OpCo, OpCo, OpCo Contact, OpCo Contact, OpCo Resolution , OpCo Resolution , Other Number of Days, Owner, Owner, Ownership, Ownership, Ownership Timeline, Ownership Timeline, Pay Code 3 (PC3), Pay Rate, Phone Number, Phone Number, Point of Contact, Point of Contact, Port Number, Port Number, Position Entered by Sourcing, Position Type, Priviledged and Confidential, Priviledged and Confidential, Problem Observed, Problem Observed, Protocol, Protocol, QA Tester, QA Tester, Rank, School, Signature ID, Signature ID, Sprint, Sub-Category, Sub-Category, Subject, Subject, Supplemental Profile, System Type, System Type, Test Environment, Test Environment, Test Environment, Timestamp, Timestamp, To, To, Total # of Incidents:, Triage Results, Victim E-mail, Victim E-mail, Victim Host Mac ID, Victim Host Mac ID, Victim HostID, Victim HostID, Victim IP, Victim IP, Victim UserID, Victim UserID, Vote, Due Date to:, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null] size=161 modCount=161>
I just want to know, what is the best syntax to gather the list of custom fields that are only at the issue ticket? Thanks
Community moderators have prevented the ability to post new answers.
Most of my code uses a construct like this:
def myCustomField = customFieldManager.getCustomFieldObjects(issue).find{it.name = "Name of custom field"}
I find that, apart from not having issues with duplicate-named CFs, I can easily port code between environments.
Jamie: in my JIRA instance, I have repetitive customfield with the same name. When I aplied this type of assignment I would get another field which is not expected
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You wouldn't, because you would only add one field with any given name to a particular context, ie issuetype and/or project. Anything else would be hugely confusing for the end user.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, I have to confess that I have 5 custom fields with the same name and same type and all of them has the global context. Now it's time to clean up my instance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would recomend you this method (attaching copy and paste sample code):
FieldScreenRenderer fieldScreenRenderer = fieldScreenRendererFactory.getFieldScreenRenderer(user, issue, IssueOperations.EDIT_ISSUE_OPERATION, false); FieldScreenRenderer fieldScreenRenderer = getUpdateFieldScreenRenderer(issueEvent.getUser(), issue); for (final FieldScreenRenderTab fieldScreenRenderTab : fieldScreenRenderer.getFieldScreenRenderTabs()) { for (final FieldScreenRenderLayoutItem fieldScreenRenderLayoutItem : fieldScreenRenderTab.getFieldScreenRenderLayoutItemsForProcessing()) { if (fieldScreenRenderLayoutItem.isShow(issue)) { OrderableField orderableField = fieldScreenRenderLayoutItem.getOrderableField(); } } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Timothy, let me explain you why: I want to get an array of customfields that are present from the issue; then from the array, I just grab the custom field by name. (Just like Jamie did).
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.