How to retrieve the specific component and project key of the jira issue using vba?

May January 15, 2018

I was able to display the values of  other fields like JIRA KEY, status, priority, description and etc in excel. except for its designated COMPONENTS and PROJECT KEY.

I already have this code, can you help me where did I get wrong and how can I display its components and project key.. 

Ex. the components for NW093 is WEB and project key is NW00A

Thanks in advance

Public Function GetJiraComponentList(ByRef projectKey As String, ByRef url As String, ByRef user As String, ByRef password As String) As Collection
If right(url, 1) <> "/" Then
url = url & "/"
End If

Dim outList As New Collection
Dim project As Dictionary
Set project = GetJson(url & "rest/api/2/project/" & projectKey, "GET", user, password)

'ƒRƒ“ƒ|[ƒlƒ“ƒg‚²‚Æ
Dim index As Long
For index = 1 To project("components").Count
Dim id As String
id = project("components")(index)("id")

Dim component As Dictionary
Set component = GetJson(url & "rest/api/2/component/" & id, "GET", user, password)
Call outList.Add(component)
Next index

Set GetJiraComponentList = outList
End Function

 

Untitled.png

 

1 answer

0 votes
Warren
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 15, 2018

Hi May

A potential better way of doing this is to use a call like 

/rest/api/2/issue/key-xxx

if you know the issue key. This returns all fields for the issue, but can be restricted by passing in the required fields

/rest/api/2/issue/key-xxx?fields=key,component,customfield_12345

As you can see, to get the components you use component (note it's singular). I don't believe you are able to get the project key

May January 15, 2018

Hi Warren, 

Thank you for your response.

How about this? Is this correct? I'm not really so sure about this, I'm still learning. 

Public Function GetIssueList(ByRef issueKey As String, _
ByRef url As String, _
Optional ByRef user As String = vbNullString, _
Optional ByRef password As String = vbNullString) As Dictionary

If right(url, 1) <> "/" Then
url = url & "/"
End If

Static map As Dictionary
If map Is Nothing Then
Set map = New Dictionary

Dim list As Collection
Set list = GetJson(url & "/rest/api/2/issue/" & issueKey, "GET", user, password)

Dim id As String
Dim Name As String
Dim index As Long
For index = 1 To list.Count
id = list(index)("id")
Name = list(index)("name")

Call map.Add(id, Name)
Next index
End If

Set GetIssueList= map
End Function

Warren
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 15, 2018

There are numerous options / API calls that you can use, as per this Cloud REST API doc. I am not clear on what you're trying to achieve, but there are calls that will return all items in a sprint, all items on a board etc. On top of that, you can pass a JQL query in to further filter the results. Then, within your code, you will need to loop through all the results, extracting the relevant info. Take a look at the link (which has been significantly updated since I last looked at it) and work out what's the best way for you to get what you're trying to achieve

Suggest an answer

Log in or Sign up to answer