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

Field creation with create_field_as_xml not working on site columns #941

Closed
tuesdayMike opened this issue Feb 19, 2025 · 1 comment
Closed
Labels

Comments

@tuesdayMike
Copy link

Hi there,

I'm trying to achieve to following: read all site columns, content types, ct to field mappings from one (DEV) sharepoint site to another (PROD) site.

But the first step to create the fields on the target site fails. The fields are not created on the target site.

`ctx = ClientContext(site_url).with_credentials(ClientCredential(client_id, client_secret))
ctx_dest = ClientContext(site_dest_url).with_credentials(ClientCredential(client_id, client_secret))

site_columns = ctx.web.fields.get().execute_query()
ctx.load(site_columns)
ctx.execute_query()

for field in site_columns:
print(f"📝 Creating field: {field.internal_name} on destination site")
try:
new_field = ctx_dest.web.fields.create_field_as_xml(field.schema_xml, field).execute_query()
except Exception as e:
print(f"An error occurred in field creation on target site: {e}")
`

new_field is created but it is not "comitted on the target site and does not show up on the target site column page.

Anything I'm doing wrong here? Is it even possible to create columns on the site level using create_field_as_xml ?

Thanks!

@tuesdayMike
Copy link
Author

I think I found the solution. Removing the "version" Element from schema_xml did the trick

@vgrem vgrem added the question label Mar 29, 2025
@vgrem vgrem closed this as completed Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants