Adding Custom Arrays with Jira API and C#

 

Imports System.Net

Imports Atlassian.Jira

Imports Newtonsoft.Json.Linq

 

Public Class MyCustomFieldValueSerializer

    Implements ICustomFieldValueSerializer

 

    Public Function FromJson(json As JToken) As String() Implements ICustomFieldValueSerializer.FromJson

        Debug.WriteLine(json)

    End Function

 

    Public Function ToJson(values() As String) As JToken Implements ICustomFieldValueSerializer.ToJson '

        Dim MySerial As New Newtonsoft.Json.JsonSerializer()

        Dim token = JToken.Parse("[{""key"" : """ & values(0) & """}]")

        Return token

    End Function

End Class

Public Class Form1

    Dim MyJira As Jira = Nothing

 

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

        Dim settings = New JiraRestClientSettings()

        settings.EnableRequestTrace = True

        settings.CustomFieldSerializers.Add("com.riadalabs.jira.plugins.insight:rlabs-customfield-default-object", New MyCustomFieldValueSerializer())

        MyJira = Jira.CreateRestClient("https://jira.FQDN.org", "YourLoginName", "YourLoginPassword", settings)

        'Init()

        CreateAndCloseTicket()

        End

 

    End Sub

 

    Public Async Function CreateAndCloseTicket() As Task

        Try

            Dim MyFields As New CreateIssueFields("IS")

            MyFields.ProjectKey = "IT"

            'MyFields.ParentIssueKey = "IT"

            Dim Myissue As Issue = MyJira.CreateIssue(MyFields)

            Myissue.Type = "User Incident"

            Myissue.Summary = "test summary"

            Myissue.Description = "test"

            'Myissue.CustomFields("awd") = map[string]String{{"value": "NA"}}

            Debug.WriteLine(Myissue.CustomFields.Count)

            'Myissue.CustomFields.AddById("customfield_12002", "{""key"" : ""TONE-15751""}")

            'Myissue.CustomFields.AddArray("Location", {"TONE-15751"})

            Myissue.CustomFields.SearchByProjectOnly = True

            'Myissue.CustomFields.AddArray("customfield_12002", "[{""key"" : ""TONE-15751""}]")

            'Myissue.CustomFields.AddById("customfield_12002", {"[{""key"" : ""TONE-15751""}]"})

            Dim MyString As String() = {"TONE-15751"}

            Myissue.CustomFields.AddArray("Location", MyString)

            'Dim MyDictonary = New Dictionary(Of String, Strin

            'MyDictonary.Add("key", "[TONE-15751]")

            'Dim MyString As New ComparableString("TONE-15751")

            'Myissue("Location") = MyString

            'Myissue.CustomFields.AddById("Location", {"TONE-15751"})

            Myissue.CustomFields.AddById("customfield_10311", "x1234")

            Myissue.CustomFields.AddById("customfield_10400", "An Account Issue")

            Myissue.SaveChanges()

        Catch ex As Exception

            Debug.WriteLine(ex.Message)

            Debug.WriteLine(ex.InnerException.Message)

            'Response Status Code: 400. Response Content: {"errorMessages":[],"errors":{"customfield_12002":"Location is required.","customfield_10311":"Best Callback Number is required.","customfield_10400":"Type of Issue is required."}}

        End Try

 

 

    End Function

 

    Public Async Function Init() As Task

        Try

            'Dim MyServiceLocator As New ServiceLocator()

            'Dim MyJira As New Jira(MyServiceLocator)

            Dim MyJiraRest As New JiraRestClientSettings

 

            Debug.WriteLine(MyJira.RestClient.Url)

 

            Dim FetchJQL As Task(Of IPagedQueryResult(Of Issue)) = MyJira.Issues.GetIssuesFromJqlAsync("project = ""IS"" AND (""Assignment Group"" = ""System Administrator"" OR Assignee in MembersOf(""WG System Administrator"")) AND status not in (Closed, Done, ""IS Director Approval"", ""Needs Approval"") AND assignee = ""24556""", 100)

            Dim Fetch As Task(Of IDictionary(Of String, Issue)) = MyJira.Issues.GetIssuesAsync({"IS-462496"})

 

            Dim MyIssuesJQL As IPagedQueryResult(Of Issue) = Await FetchJQL

            Dim MyIssues As IDictionary(Of String, Issue) = Await Fetch

 

            For Each MyEntry In MyIssues

                Debug.WriteLine(MyEntry.Key)

            Next

 

            Debug.WriteLine("Found issues count:" & MyIssuesJQL.Count)

            For Each MyEntry As Issue In MyIssuesJQL

                Debug.WriteLine(MyEntry.Updated.ToString() & " " & MyEntry.Key.ToString & " " & MyEntry.Summary)

            Next

 

        Catch ex As Exception

            Debug.WriteLine(ex.Message)

        End Try

    End Function

End Class

Popular Posts

Leave a Reply

Your email address will not be published. Required fields are marked *