locked
list template and associated workflow RRS feed

  • Question

  • I have an requirement where I have created an standard list with that list there are 2 workflow attached to it.

    so requirement is I want to create an list using list template which I have saved for pervious list.so when list is created from template I want workflow should be automatically get attached to new list as well.

    I want to archive  this by oob and designer workflow only .

    Please help me in this .

    Regards,

    lalit kasa


    Regards, Lalit Kasa lalit.kasa88@hotmail.com

    Wednesday, May 11, 2016 10:33 AM

Answers

  • Hi,

    There is not any out of the box way to include workflow with list template using UI approach save list as template, You can use the powershell script to get all workflow associated with your lsit  and save them it will save as xml.

    $myWFColl = $myList.get_WorkflowAssociations()

    For ($i=0; $i -lt $myWFColl.get_Count(); $i++)

    {

       $thisAssociation = $myWFColl.get_item($i)

       $saveTo = $localFolder + $thisAssociation.get_name() + ".xml"

       $exportedAssociation = $myWFColl.get_item($i).get_associationdata()

       $exportedAssociation >> $saveTo

    }

    In your destination environment you can use the Import List command and attach the saved workflow template to your list.

    $newWeb = Get-SPWeb -Identity $newSiteAddress #SPWeb object

    $newList = $newWeb.GetList($newListPath) #SPList object

    $newHistoryList =  $newWeb.GetList("/siteURL/Lists/Workflow%20History")

    $newTaskList = $newWeb.GetList("/siteURL/Lists/Tasks")

         $xmlFile = $localFolder + "File Validation.xml"//Name of your workflow

        $associationData  = Get-Content $xmlFile

        $newListWFTemplates = $newWeb.get_WorkflowTemplates() #SPWorkflowTemplateCollection object

        $newFeedback = $newListWFTemplates.GetTemplateByName("WF Name", "en-us")

        $validationAssociation = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListAssociation($newFeedback, "File Validation", $newTaskList, $newHistoryList)

        $validationAssociation.set_AssociationData($associationData)

        $validationAssociation.set_AutoStartCreate("true")

        $validationAssociation.set_AllowManual(0)

         $xmlFile = $localFolder + "Approval Workflow.xml"//Workflow Name

        $associationData  = Get-Content $xmlFile

        $newApproval = $newListWFTemplates.GetTemplateByName("Approval Workflow", "en-us")

        $approvalAssociation = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListAssociation($newApproval, "Approval Workflow", $newTaskList, $newHistoryList)

        $approvalAssociation.set_AssociationData($associationData)

        $approvalAssociation.set_AutoStartCreate("false")

        $approvalAssociation.set_AllowManual(0)

        $approvalAssociation.set_AutoCleanupDays(2555)

        $approvalGUID = $approvalAssociation.get_Id();

        $newList.set_DefaultContentApprovalWorkflowId($approvalGUI)

        $xmlFile = $localFolder + "Collect Feedback Workflow.xml"

        $associationData  = Get-Content $xmlFile

        $newApproval = $newListWFTemplates.GetTemplateByName("Collect Feedback Workflow", "en-us")

        $collectAssociation = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListAssociation($newApproval, "Collect Feedback Workflow", $newTaskList, $newHistoryList)

        $collectAssociation.set_AssociationData($associationData)

        $collectAssociation.set_AutoStartCreate("false")

        $collectAssociation.set_AllowManual(1)

        $collectAssociation.set_AutoCleanupDays(2555)

        $newWFAssociationColl = $newList.get_WorkflowAssociations()

        $newWFAssociationColl.Add($validationAssociation)

        $newWFAssociationColl.Add($collectAssociation)

        $newWFAssociationColl.Add($approvalAssociation)

        $newList.Update()


    KRISHANA KUMAR

    SharePoint Architect

    Mosstechnet-kk.com

     

    Please click "Mark As Answer" if this post solves your problem or "Vote As Helpful" if it was useful


    Wednesday, May 11, 2016 2:38 PM