2

I'm attempting to introduce a new site column into a widely-used content type. For several reasons, I want the new column to fit in directly above another existing column.

I'm able to reorder the columns in the content type without a hitch, and update the content type, passing the flag that indicates the new column should be propagated to all lists that use the content type.

All of that works cleanly. However, each list that uses the content type maintains its own copy of the content type, and although the new column is inserted into the list's own copy of the content type, the columns are not reordered. If I want that to happen, I have to manually go to that content type and reorder the columns.

Am I doing something wrong or missing a step?

The relevant (Powershell) code looks like this:

    #... machinations to reorder the columns ...
    $ct.FieldLinks.Reorder($ctFieldSequence)
    $ct.Update($true) # causes all lists that use this CT to be updated.

Thanks in advance
Josh

  • 1
    You aren't missing anything or doing anything wrong, that's just how it works. You'll have to extend your script to find all instances in your lists where it is used and update them accordingly. – Eric Alexander Nov 16 '16 at 16:28
  • So far, so good. There's actually a usage record in the Content Type, and I can use that to find out which list it's used in (with a bit of twiddling). And all seems to go well in reordering that copy of the content type, except that SharePoint seems to have a nasty habit of putting one of those columns at the bottom of the list, even when I specifically tell it to put it higher up. And that, of course, is really irritating. Like SharePoint itself does, I leave the hidden columns alone; when I included those, it turned the column order into potato salad. What could be going wrong? – Josh Korn Nov 21 '16 at 18:14
0

Sorry, this isn't an answer, but I can't find any other way to post the relevant code:

    # parameters are: $ct (content type), $field (field to insert), $aheadOf
    # n.b. the individual FieldLink.Name is actually its Internal Name.

    [string[]] $ctFieldSequence = @()

    Foreach ($link in $ct.FieldLinks)
    {
        # Insert the magic field in its desired position
        if ($link.DisplayName.Contains($aheadOf)) {
            $ctFieldSequence += $field.InternalName
        }

        # ignore ContentType
        if ($link.Name -eq 'ContentType') {
            continue;
        }

        # all other fields
        if (-not ($link.DisplayName -eq $field.InternalName) -and (-not $link.Hidden)) {
            $ctFieldSequence += $link.Name
        }
    }

    # Write-Host 'Updating order of columns'
    $ct.FieldLinks.Reorder($ctFieldSequence)
    $ct.Update()
    return $ctFieldSequence

This code does the same thing as the code on the ChangeFieldOrder page (except for column numbers), in that it specifically excludes Hidden columns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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