Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I don't know why but when I try to bind a list with my content type, fields having a status to "Required" in my content type are not Required at all in my List.

I'm binding the field with this function :

function bindContentType($urlCollec, $xml, $lg){
Display-Info("Begin : Adding a Content Type")
$xmltypeContents = [xml](Get-Content $xml)
$typeContents = $xmltypeContents.contentTypes

foreach($typeContent in $typeContents.contentType){
    $url = $urlCollec+$typeContent.url
    $web = Get-SPWeb($url)

    $listTitle = GetValueByLanguage $lg $typeContent.list
    $list = $web.Lists[$listTitle]
    $webRoot = Get-SPWeb $urlCollection
    if($list -ne $null){
        $newCT = $webRoot.AvailableContentTypes[$typeContent.ctName]
        $list.ContentTypesEnabled = $true
        if($newCT -eq $null){
            Display-Error("The content type "+$typeContent.ctName+" does not exists")
        }
        else{
            # Add the content type to the list.
            if (!$list.IsContentTypeAllowed($newCT)){
                Display-Error("The content type is not allowed on the list")
            }
            elseif ($list.ContentTypes[$newCT.Name] -ne $null){
                Display-Warning("The content type name is already in use on the list");
            }
            else{
                $addingnewCt = $list.ContentTypes.Add($newCT);
                Display-Success("The content type "+$typeContent.ctName+" was successfully added to the list "+$listTitle);
            }

            $list.Update()
            if($typeContent.raz -eq 1)  {#Delete Associate type content 
                foreach($content in $list.ContentTypes){
                    if(!($content.Name -eq $typeContent.ctName)){
                        $list.ContentTypes.Delete($content.ID)

                    }
                }
            }
        }
    }
    else{
        Display-Error("The list "+$listTitle+" does not exists")
    }
}
Display-Info("End : Adding a Content Type ")
}

Do you have some ideas where it can come from ?

Thanks

share|improve this question
add comment

1 Answer 1

Grab the web version of the content type, grab the FieldLink (FieldRef) and update that.

e.g. in pseudo code:-

SPContentType contentType = web.ContentTypes[contentTypeName];
SPField field = contentType.Fields[fieldName];
contentType.FieldLinks[field.Id].Required = true;
contentType.Update();
share|improve this answer
    
Hey, I've tried this, but still doesn't work when I bind the list to the content type :s –  Thoma Bigueres Jul 16 '12 at 8:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.