Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get the jira issue id from the value of a custom field

Pedro Oliva Rodríguez January 29, 2024

I have a custom field that assosiciates a jira issue with another. I am creating a Script Field and for that I need the id of that jira issue that is assosiacted, but "issue.getCustomFieldValue(customField)" returns an Object object, I can´t get the id for that.

Is ther a way to parse it into a JiraIssue type? Can I get the id of that issue via another way?

Thanks.

1 answer

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2024

Welcome to the Atlassian Community!

This suggests that your customField may be a select list, although I would expect that to return an object of type "option", not just "object".  Getting an "object" suggests that it is a custom field of a non-native type, not a standard Jira issue field.

If that is the case, you'll need to consult the docs for the app that is providing the field to find out how to interrogate the object for the data you need.

I would also question why you're doing this, when you could be using issue links to associate two issues together (they're easier to work with in code as well...)

Pedro Oliva Rodríguez January 29, 2024

Yeah, the custom field is a select list, the customer wants to automate the process of linking 2 issues, whenever you select a issue in this custom field, the 2 issues must link together.

 

Could this custom field be configure so that it returns an IssueType? Or the only way is via code?

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2024

No, select lists are made of options.

You can get the name of an option with issue.getCustomFieldValue(customField).getName()

Seems odd to me to want to link an issue to another one by using a select list, when the issue link function already does it.

Pedro Oliva Rodríguez January 30, 2024

That is what I asked them, the answer was that this custom field makes a child reference to an issue in another issue. They want the child to be linked to the parent issue automatically

My approach was using ComponentAccessor.getIssueLinkManager().createIssueLink(sourceIssueId, destinationIssueId, issueLinkTypeId, sequence, user)

Only things I´m lacking is "destinationIssueId" which I´m trying to get retrieving the value of the custom field. Still wondering what sequence even is...

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2024

Ok, on both a technical and procedural level, the field does not make a child reference.  That is done with Sub-tasks, Issues, Epics, and any other issue levels you put in a hierarchy above Epic.  This field is never going to act in the way a "parent" field will.

But hey, if that's what they think they want to do, it's not for us to refuse, we can only question why they're botching something this way, explain there are better ways to do it, and then do what they think they need if they don't adopt the better approaches.

The field contains some reference to another issue.  The value in the field is not an issue, so you can't use it in your "createIssueLink" call.

You'll need to ask them how the field options relate to the issues they represent.  Issue key?  Issue id?  Another field on an issue?

Suggest an answer

Log in or Sign up to answer