Skip to content

Unable to add existing site column to content typ (ct.field_links.add()) #942

Open
@tuesdayMike

Description

@tuesdayMike

Hi,

I'm struggling to add existing site columns to content type.

Code:
`
field_target = ctx_dest.web.fields.get_by_internal_name_or_title(field.title).execute_query()
print(f" - Mapping Field: {field_target.internal_name} Target-ID: {field_target.id}")

field_links = ct_target.field_links.add(field_target).execute_query()
`
The field_target is found and of type 'office365.sharepoint.fields.field.Field'.

The error is:

`Traceback (most recent call last):
File "/home/joe/.local/lib/python3.10/site-packages/office365/runtime/client_request.py", line 37, in execute_query
response = self.execute_request_direct(request)
File "/home/joe/.local/lib/python3.10/site-packages/office365/runtime/client_request.py", line 101, in execute_request_direct
response.raise_for_status()
File "/usr/lib/python3/dist-packages/requests/models.py", line 943, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://joe.sharepoint.com/sites/Joe_PROD/_api/Web/ContentTypes('0x0100DBB1EA60214E52428BCC389XXXSSSAAA')/FieldLinks

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/joe/reporting/sharepoint_list_mgmt/sp_site_config_reproduce.py", line 189, in
field_link = ct_target.field_links.add(field_target).execute_query()
File "/home/joe/.local/lib/python3.10/site-packages/office365/runtime/client_object.py", line 55, in execute_query
self.context.execute_query()
File "/home/joe/.local/lib/python3.10/site-packages/office365/runtime/client_runtime_context.py", line 173, in execute_query
self.pending_request().execute_query(qry)
File "/home/joe/.local/lib/python3.10/site-packages/office365/runtime/client_request.py", line 41, in execute_query
raise ClientRequestException(*e.args, response=e.response)
office365.runtime.client_request_exception.ClientRequestException: ('-2147024809, System.ArgumentException', "Die Spalte 'Absender' ist nicht vorhanden. Möglicherweise wurde sie von einem anderen Benutzer gelöscht. https://joe.sharepoint.com/sites/Joe_PROD ", "400 Client Error: Bad Request for url: https://joe.sharepoint.com/sites/Joe_PROD/_api/Web/ContentTypes('0x0100DBB1EA60214E52428BCC389XXXSSSAAA')/FieldLinks")
`

Activity

tuesdayMike

tuesdayMike commented on Feb 20, 2025

@tuesdayMike
Author

I tried switching to plain vanilla http requests (SP Rest API) but âlways get to the 404 point. This limitations seems to be the problem:

Site Columns cannot be added to a content type using the REST service.

Source: https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj245869(v=office.15)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @vgrem@tuesdayMike

      Issue actions

        Unable to add existing site column to content typ (ct.field_links.add()) · Issue #942 · vgrem/Office365-REST-Python-Client