powershell - Update SharePoint Online columns/content types with CSOM -


i have following csom script update site columns , push down changes:

add-type -path "libraries\microsoft.sharepoint.client.dll"  add-type -path "libraries\microsoft.sharepoint.client.runtime.dll"   $weburl = "enter_url_here"  $username = "enter_username_here" $password = "enter_password_here" $securepass = convertto-securestring $password -asplaintext -force  $ctx = new-object microsoft.sharepoint.client.clientcontext($weburl) $ctx.credentials = new-object microsoft.sharepoint.client.sharepointonlinecredentials($username, $securepass)  #add description "other category" field $fieldtitle = "other category" $fielddesc = "search existing name before adding new entries" $field = $ctx.site.rootweb.fields.getbyinternalnameortitle($fieldtitle) $field.description = $fielddesc $field.updateandpushchanges($true)  #add description "initiator location" field $field2title = "initiator location" $field2 = $ctx.site.rootweb.fields.getbyinternalnameortitle($field2title) $field2.description = $fielddesc $field2.updateandpushchanges($true)  #setting "main-category" field required/mandatory $field3title = "main-category" $field3 = $ctx.site.rootweb.fields.getbyinternalnameortitle($field3title) $field3.required = $true $field3.updateandpushchanges($true)  $ctx.executequery() 

the above fields/columns part of site content type called "main documents".

so far works fine, "main-category" field how set "required" @ content type level? @ moment being set @ site column level, easiest way achieve this?

many thanks.

use contenttype.fieldlinks property field references in content type , fieldlink.required property set value specifies whether field requires value.

example

how set required property field via content type:

$ct = $ctx.web.contenttypes.getbyid($ctid) #get content type  $fieldlink = $ct.fieldlinks.getbyid($fieldid) #get field link $fieldlink.required = $true $ct.update($true) $ctx.executequery()  

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -