-
-
Notifications
You must be signed in to change notification settings - Fork 370
Expand file tree
/
Copy pathcreate_field.py
More file actions
34 lines (24 loc) · 1.41 KB
/
Copy pathcreate_field.py
File metadata and controls
34 lines (24 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Demonstrates how to create a taxonomy field on a list.
https://learn.microsoft.com/en-us/sharepoint/dev/apis/rest-api/taxonomy
"""
import argparse
from office365.sharepoint.client_context import ClientContext
from tests.settings import client_id, client_secret, team_site_url, tenant
def main():
parser = argparse.ArgumentParser(description="Create taxonomy fields on a list")
parser.add_argument("--list-title", default="Requests", help="list title")
parser.add_argument("--term-set-id", default="3b712032-95c4-4bb5-952d-f85ae9288f99", help="term set id")
parser.add_argument("--field-name", default="Country", help="single-value taxonomy field name")
parser.add_argument("--multi-field-name", default="Countries", help="multi-value taxonomy field name")
args = parser.parse_args()
ctx = ClientContext(team_site_url).with_client_secret(tenant, client_id, client_secret)
custom_list = ctx.web.lists.ensure_list(args.list_title).get().execute_query()
print("1. Adding a taxonomy field into list '{0}'...".format(custom_list.title))
custom_list.fields.create_taxonomy_field(args.field_name, args.term_set_id).execute_query()
print("2. Adding a taxonomy field into list '{0}'...".format(custom_list.title))
custom_list.fields.create_taxonomy_field(
args.multi_field_name, args.term_set_id, allow_multiple_values=True
).execute_query()
if __name__ == "__main__":
main()