SPContentType.UpdateWorkflowAssociationsOnChildren Method (Boolean, Boolean, Boolean, Boolean)

Propagates changes in this content type’s workflow associations to content types that are derived from this content type or to instances of this content type that have been applied to lists, or to both. Optionally marks objects touched by the operation as changed. Also optionally suppresses exceptions that are thrown because a child is either sealed or read-only.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Sub UpdateWorkflowAssociationsOnChildren ( _
    bGenerateFullChangeList As Boolean, _
    bPushdownDerivedCT As Boolean, _
    bPushdownListCTs As Boolean, _
    bThrowOnSealedOrReadOnly As Boolean _
)
'Usage
Dim instance As SPContentType
Dim bGenerateFullChangeList As Boolean
Dim bPushdownDerivedCT As Boolean
Dim bPushdownListCTs As Boolean
Dim bThrowOnSealedOrReadOnly As Boolean

instance.UpdateWorkflowAssociationsOnChildren(bGenerateFullChangeList, _
    bPushdownDerivedCT, bPushdownListCTs, _
    bThrowOnSealedOrReadOnly)
public void UpdateWorkflowAssociationsOnChildren(
    bool bGenerateFullChangeList,
    bool bPushdownDerivedCT,
    bool bPushdownListCTs,
    bool bThrowOnSealedOrReadOnly
)

Parameters

  • bGenerateFullChangeList
    Type: System.Boolean

    true to mark all SPContentType objects touched by this operation as changed; false does not.

  • bPushdownDerivedCT
    Type: System.Boolean

    true to propagate changes to content types derived from this content type; otherwise false.

  • bPushdownListCTs
    Type: System.Boolean

    true to propagate changes to list content types based on this content type; otherwise false.

  • bThrowOnSealedOrReadOnly
    Type: System.Boolean

    true to throw an exception on encountering a content type that is sealed or read-only; otherwise false.

Exceptions

Exception Condition
SPContentTypeSealedException

The Sealed property of a child of this content type has a value of true.

SPContentTypeReadOnlyException

The ReadOnly property of a child of this content type has a value of true.

Remarks

Use this method to optionally propagate changes in the parent content type’s workflow associations down to either derived or list versions of the content type, or both. If you pass false as the argument to the bGenerateFullChangeList parameter, SPContentType objects that are touched by this operation are not marked as changed and OnChanged events are not raised. Passing false as the argument to the bThrowOnSealedOrReadOnly parameter suppresses exceptions thrown when changes cannot be written to any child because it is marked as sealed or read-only.

Examples

Dim siteCollection As SPSite = New SPSite("https://localhost")
Dim site As SPWeb = siteCollection.OpenWeb()

Dim siteContentType As SPContentType = site.ContentTypes("Test Document")
Dim taskListTitle As String = "Tasks"
Dim historyListTitle As String = "Workflow History"
Dim workflowName As String = "Red-Yellow-Green"

' Get a template.
Dim workflowTemplate As SPWorkflowTemplate = Nothing
For Each template As SPWorkflowTemplate In site.WorkflowTemplates
    workflowTemplate = template
    ' We'll take a template everyone has.
    If workflowTemplate.Name = "Three-state" Then
        Exit For
    End If
Next template

' Create an association.
Dim workflowAssociation As SPWorkflowAssociation = _
          SPWorkflowAssociation.CreateSiteContentTypeAssociation(workflowTemplate, _
                                                                 workflowName, _
                                                                 taskListTitle, _
                                                                 historyListTitle)

' Add the association to the content type or update it if it already exists.
Console.Write("Workflow association {0} has been ", workflowAssociation.Name)
If siteContentType.WorkflowAssociations.GetAssociationByName(workflowAssociation.Name, site.Locale) Is Nothing Then
    siteContentType.AddWorkflowAssociation(workflowAssociation)
    Console.WriteLine("added")
Else
    siteContentType.UpdateWorkflowAssociation(workflowAssociation)
    Console.WriteLine("updated")
End If

' Propagate to children of this content type.
siteContentType.UpdateWorkflowAssociationsOnChildren(False, True, True, False) ' Suppress exceptions

' Clean up.
site.Dispose()
siteCollection.Dispose()
SPSite siteCollection = new SPSite("https://localhost");
SPWeb site = siteCollection.OpenWeb();

SPContentType siteContentType = site.ContentTypes["Test Document"];
string taskListTitle = "Tasks";
string historyListTitle = "Workflow History";
string workflowName = "Red-Yellow-Green";

// Get a template.
SPWorkflowTemplate workflowTemplate = null;
foreach (SPWorkflowTemplate template in site.WorkflowTemplates)
{
    workflowTemplate = template;

    // We'll take a template everyone has.
    if (workflowTemplate.Name == "Three-state") break;
}

// Create an association.
SPWorkflowAssociation workflowAssociation =
    SPWorkflowAssociation.CreateSiteContentTypeAssociation(workflowTemplate,
                                                           workflowName,
                                                           taskListTitle,
                                                           historyListTitle);

// Add the association to the content type or update it if it already exists.
Console.Write"Workflow association {0} has been ", workflowAssociation.Name);
if (siteContentType.WorkflowAssociations.GetAssociationByName(workflowAssociation.Name, site.Locale) == null)
{
    siteContentType.AddWorkflowAssociation(workflowAssociation);
    Console.WriteLine("added.");
}
else
{
    siteContentType.UpdateWorkflowAssociation(workflowAssociation);
    Console.WriteLine("updated.");
}

// Propagate to children of this content type.
siteContentType.UpdateWorkflowAssociationsOnChildren(false,  // Do not generate full change list
                                                     true,   // Push down to derived content types
                                                     true,   // Push down to list content types
                                                     false); // Do not throw an exception if sealed or readonly  

site.Dispose();
siteCollection.Dispose();

See Also

Reference

SPContentType Class

SPContentType Members

UpdateWorkflowAssociationsOnChildren Overload

Microsoft.SharePoint Namespace

AddWorkflowAssociation

Other Resources

Introduction to Workflows in SharePoint Foundation

Workflow Stages