Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting custom fields doesn't work as expected #80

Open
ghostravenstorm opened this issue Nov 5, 2020 · 1 comment
Open

Getting custom fields doesn't work as expected #80

ghostravenstorm opened this issue Nov 5, 2020 · 1 comment

Comments

@ghostravenstorm
Copy link

ghostravenstorm commented Nov 5, 2020

Problem:
Using the CustomFields function on a Card reciever returns 0 data

Code:

func main () {

   appKey := `<CONFIDENTIAL>`
   token := `<CONFIDENTIAL>`
   boardId := `<CONFIDENTIAL>`

   client := trello.NewClient(appKey, token)
   board, err := client.GetBoard(boardId, trello.Defaults())
   if err != nil {
      fmt.Println(err)
      return
   }

   customFields, err := board.GetCustomFields(trello.Defaults())
   if err != nil {
      fmt.Println(err)
   }

   fmt.Println("Printing custom field objects on the board")
   for _, v := range customFields {
      fmt.Printf("%+v", v)
      fmt.Println()
   }

   lists, err := board.GetLists(trello.Defaults())
   if err != nil {
      fmt.Println(err)
      return
   }

   for _, list := range lists {
     cards, err := list.GetCards(trello.Defaults())
     if err != nil {
        fmt.Println(err)
        continue
     }

     fmt.Println("Number of cards in list:", len(cards))
     var count int = 0

     for _, card := range cards {

        count++
       
        /// It is unclear if the Card slice this function requires should come from Board.GetCustomFields, or if it should be an empty slice.
        customFieldMap := card.CustomFields(customFields)
        fmt.Println("Number of custom fields on card", count, ":", len(customFieldMap))
        fmt.Println("Number of custom field items on card", count, ":", len(card.CustomFieldItems))

     }
   }
}

Output:

Printing custom field objects on the board
&{ID:5fa073a5eedccb1a273b7db2 IDModel:5fa0710b81d40785e7e8d06a IDModelType:board FieldGroup:9fdff5d309838d346add25a8e5260d5c27b4dbcc98e5c3d0da85b5ec991e37f7 Name:Created Pos:16384 Display:{CardFront:false} Type:date Options:[]}
&{ID:5fa073afa41de270281aa94c IDModel:5fa0710b81d40785e7e8d06a IDModelType:board FieldGroup:9c0fdca40714ca5c1f07cf19dce17821e5929624a57ae4a1f8fcd938cceca945 Name:Start Pos:32768 Display:{CardFront:false} Type:date Options:[]}
&{ID:5fa073b63f96c845ec9dd0c7 IDModel:5fa0710b81d40785e7e8d06a IDModelType:board FieldGroup:fc5e9fa90b20867f3c27c61e67e33b2e583653abd693703800c04456ec854114 Name:End Pos:49152 Display:{CardFront:false} Type:date Options:[]}
&{ID:5fa0741e1d9d2c2bc833788f IDModel:5fa0710b81d40785e7e8d06a IDModelType:board FieldGroup:c77db228ea2700530db145e0d91ab5129ce52883999ccc42693e6dae7d2c2ad3 Name:Charge Pos:65536 Display:{CardFront:true} Type:list Options:[0xc0000d64b0 0xc0000d6500 0xc0000d6550]}
&{ID:5fa074286ef27c133d0186bb IDModel:5fa0710b81d40785e7e8d06a IDModelType:board FieldGroup:7602b2a97184edb3beeb5b0076b88f065146bd5797726754fc6c96e099d15abc Name:Workload Pos:81920 Display:{CardFront:true} Type:list Options:[0xc0000d65a0 0xc0000d65f0 0xc0000d6640 0xc0000d6690 0xc0000d66e0 0xc0000d6730]}
&{ID:5fa0746a39b64c850400b920 IDModel:5fa0710b81d40785e7e8d06a IDModelType:board FieldGroup:b0cddfb41bc9462347387c37077a2de5338a50c797e04f3cf0adb6ae2344e83c Name:Priority Pos:98304 Display:{CardFront:true} Type:list Options:[0xc0000d6780 0xc0000d67d0 0xc0000d6820 0xc0000d6870 0xc0000d68c0 0xc0000d6910 0xc0000d69b0]}
&{ID:5fa079eb3c04d6016ef994e2 IDModel:5fa0710b81d40785e7e8d06a IDModelType:board FieldGroup:e8620327b22fc5e743a35720260ad7f03a0edaef6e64e3c47f37f04f09ce4747 Name:Status Pos:114688 Display:{CardFront:true} Type:list Options:[0xc0000d6a50 0xc0000d6aa0 0xc0000d6af0 0xc0000d6b40 0xc0000d6b90]}
Number of cards in list: 5
Number of custom fields on card 1 : 0
Number of custom field items on card 1 : 0
Number of custom fields on card 2 : 0
Number of custom field items on card 2 : 0
Number of custom fields on card 3 : 0
Number of custom field items on card 3 : 0
Number of custom fields on card 4 : 0
Number of custom field items on card 4 : 0
Number of custom fields on card 5 : 0
Number of custom field items on card 5 : 0
Number of cards in list: 2
Number of custom fields on card 1 : 0
Number of custom field items on card 1 : 0
Number of custom fields on card 2 : 0
Number of custom field items on card 2 : 0
Number of cards in list: 6
Number of custom fields on card 1 : 0
Number of custom field items on card 1 : 0
Number of custom fields on card 2 : 0
Number of custom field items on card 2 : 0
Number of custom fields on card 3 : 0
Number of custom field items on card 3 : 0
Number of custom fields on card 4 : 0
Number of custom field items on card 4 : 0
Number of custom fields on card 5 : 0
Number of custom field items on card 5 : 0
Number of custom fields on card 6 : 0
Number of custom field items on card 6 : 0
Number of cards in list: 1
Number of custom fields on card 1 : 0
Number of custom field items on card 1 : 0
Number of cards in list: 4
Number of custom fields on card 1 : 0
Number of custom field items on card 1 : 0
Number of custom fields on card 2 : 0
Number of custom field items on card 2 : 0
Number of custom fields on card 3 : 0
Number of custom field items on card 3 : 0
Number of custom fields on card 4 : 0
Number of custom field items on card 4 : 0

Expectation:
Using the CustomFields function on a Card reciever should provide data on what the value is for each custom field

How to reproduce:
Copy the above example code in your own main program, fill in the appKey, token, and boardId fields to a Trello board you control, then observe the output.

Notes:
It seems that the CustomFieldItems JSON serialized property on Card is empty to begin with, so the loop in Card.CustomFields skips over it.

@harpchad
Copy link

Try passing trello.Arguments{"customFieldItems":"true"} to GetCards instead of trello.Defaults()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants