APIs & Integrations

AJLaPorte_diagr
Key Advisor

Solved: Storing author name data in a choice fields returns "Invalid Choices List"

Hello,

I am having problems trying to get a list of others as choices in choice module. I am able to get the list to the point of pulling everything correctly, the only issue is that I get “Invalid Choices List: [Dana Smith]”. Below is the code I am using:

{% set authors_choice = [] %}
{% set author_list = blog_authors('default', 20) %}
{% for author in author_list|sort(False,False,'display_name') %}
    {{ authors_choice.append(author) }}
{% endfor %}
{% choice "author_two" label="Choose A Secondary Author", value="", choices="{{authors_choice}}", export_to_template_context=True %}

If I do it this way, there are no errors, but then it would have to be manually updated:

{% set my_options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] %}`
{% choice "author_two" label="Choose A Secondary Author", value="", choices="{{my_options}}", export_to_template_context=True %}

I’m not sure what the difference in the value list is since it is essentially the same type of data set being used.

Any help would be much appreciated.

0 Upvotes
6 Replies 6
3PETE
HubSpot Employee
HubSpot Employee

Solved: Storing author name data in a choice fields returns "Invalid Choices List"

@ajlaporte can you post what blog_authors is as well?

0 Upvotes
AJLaPorte_diagr
Key Advisor

Solved: Storing author name data in a choice fields returns "Invalid Choices List"

@pmanca Honestly, I dont even need to include the author_list portion of code and instead can do this:

{% set authors_choice = [] %}
{% for author in blog_authors('default', 20) %}
    {{ authors_choice.append(author) }}
{% endfor %}
{% choice "author_two" label="Choose A Secondary Author", value="", choices="{{authors_choice}}", export_to_template_context=True %}

Which still results in an Invalid Choices list. If you’d like I can send you the portal ID and link to the template where this is all at so you can see it.

0 Upvotes
AJLaPorte_diagr
Key Advisor

Solved: Storing author name data in a choice fields returns "Invalid Choices List"

I was able to figure out the issue. It needed to be stored as a value label pair.

0 Upvotes
asa_curry
Member

Solved: Storing author name data in a choice fields returns "Invalid Choices List"

Hi @ajlaporte!

I know this thread is very told, but would you be able to post your solutions for this? I’m trying to do the same basic thing and I haven’t been able to figure out the syntax to pass in the value label pair and to get past the error.

Thank you!

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Solved: Storing author name data in a choice fields returns "Invalid Choices List"

@ajlaporte I’m glad you figured it out . Thanks for letting us know the solution

0 Upvotes
AJLaPorte_diagr
Key Advisor

Solved: Storing author name data in a choice fields returns "Invalid Choices List"

@pmanca The code above pulls in a list of blog authors using the blog_authors HubL function (http://designers.hubspot.com/en/docs/hubl/hubl-supported-functions#blog-authors). It’s then setting author_list to the this and using the for loop to go through it. Inside the for loop, I have it appending the author to the authors_choice variable so once the loop is completed, all the authors (limited to 20 in this case) will be in an array for the authors_choice variable.

This array is what is coming back as an Invalid choices list.

0 Upvotes