Skip to content

Confusing error when creating a choice field on a list #873

@Midnighter

Description

@Midnighter

There's an example for creating a choice field using the add_choice_field method, which adapted to a list looks like:

from office365.sharepoint.client_context import ClientContext
from tests import create_unique_name, test_client_credentials, test_team_site_url

client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
target_list = client.web.lists.get_by_title("My List")

field_name = create_unique_name("ChoiceField")

choices = ["Not Started", "In Progress", "Completed", "Deferred"]
field = target_list.fields.add_choice_field(title=field_name, values=choices).execute_query()

That example works completely fine for me, too. However, what confuses me is that when I want to use FieldCreationInformation I get a 400 Bad Request. This confuses me greatly, as the add_choice_field seems to do the same thing internally.

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.fields.creation_information import FieldCreationInformation
from office365.sharepoint.fields.type import FieldType
from tests import create_unique_name, test_client_credentials, test_team_site_url

client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
target_list = client.web.lists.get_by_title("My List")

field_name = create_unique_name("ChoiceField")

choices = ["Not Started", "In Progress", "Completed", "Deferred"]
field = target_list.fields.add(FieldCreationInformation(field_name, FieldType.Choice, choices=choices)).execute_query()

This happens on Python 3.11 with version 2.5.10.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions