0

The source of a column in a content type can be retrieved in the User Interface as follows:

  1. Go to List Settings
  2. Click on Advanced Settings, set Allow Management of Content Types to Yes and click OK to return to the List Settings page
  3. The Content Types section should now be visible. Click on the content type to view the columns in the content type
  4. If the column comes from the content type's parent (or ancestor), the "source" will be marked with the appropriate content type.

Example: for a calendar list, the Source of the Title column will be Item, the Source of Location, Start Time, End Time, etc. will be Event, and the source of any columns manually added to the list will be blank.

How can the "Source" be retrieved programatically - i.e. C# (SSOM/CSOM), PowerShell, etc.

1
  • If there is no mechanism for retrieving this value, I will need to iterate up the ancestor chain, checking for "most ancient" ancestor that contains each column.
    – Hutch
    Commented Jun 9, 2015 at 20:56

1 Answer 1

1

I've been trying to do the same, and I don't think there's a direct way of doing this.

SPContentType does have a Parent property and SPFieldCollection does have a ContainsFieldWithStaticName method, so you can quickly check if a field exists in the parent to see if it's been added to the content type at the current level.

if ($contentType.Parent.fields.ContainsFieldWithStaticName($fieldName) -eq $false) {
  ...
}

That was all I needed to do, so I stopped there... but a quick bit of recursion gets the name of the content type that had the field added

function GetSource($contentType, $fieldName) {
    if (!$contentType.Fields.ContainsFieldWithStaticName($fieldName)) { Write-Output "" }
    if (!$contentType.Parent) { Write-Output $contentType.Name }
    if ($contentType.Parent.fields.ContainsFieldWithStaticName($fieldName)) { Write-Output (GetSource $contentType.Parent $fieldName) }
    Write-Output $contentType.Name
}
1
  • This is what I ended up doing as well, more or less.
    – Hutch
    Commented Dec 15, 2015 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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