Friday, February 17, 2012

Issues after deploying SharePoint 2010 Designer Reusable Workflow

Hi,

I got the below issue from one of our colleague in our practise.

Issue
We need to deploy SharePoint designer reusable workflow for approval process to other site collections. We try to get the WSP file from SharePoint Designer using ‘Save as Template’. We try to Import Reusable workflow to Visual Studio using WSP generated above. We try deploy it to other sites and then we are facing the following issues.
1. When we try to Add a workflow to a list, the deployed workflow is listed in All content types. And when we try to select the custom content type we generated, the workflow is not displayed.
2. After adding that workflow to that list, when we initiate that workflow to a list item, it is creating a task. But when we try to edit that task form it is giving page not found error.

Considering this scenario, it would help us if anyone can provide us the deployment approach for a re-usable SharePoint Designer 2010 workflow as a WSP solution package.

After understanding the above,one of my teammate gave the solution as below i.e creating the feature and attaching to workflow association.


Reply
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{

SPWorkflowTemplate workflowTemplate = null; // Workflow template
SPWorkflowAssociation workflowAssociation = null; //Workflow association
SPList historyList = null; // Workflow history list
SPList taskList = null; // Workflow tasks list
SPList list = null;
//Sharepoint List
using (SPSite site = (SPSite)properties.Feature.Parent)
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
workflowTemplate = web.WorkflowTemplates.GetTemplateByName(SPPROCWorkflowAssociationConstants.WorkFlowName, System.Globalization.CultureInfo.CurrentCulture);
list = web.Lists[SPPROCWorkflowAssociationConstants.TargetLibrary];
historyList = web.Lists[SPPROCWorkflowAssociationConstants.HistoryList];
taskList = web.Lists[SPPROCWorkflowAssociationConstants.TaskList];
SPContentType ctType = list.ContentTypes[SPPROCWorkflowAssociationConstants.ContentType];
try
{
// Create workflow association
workflowAssociation = SPWorkflowAssociation.CreateListContentTypeAssociation(workflowTemplate, SPPROCWorkflowAssociationConstants.WorkFlowName, taskList, historyList);
// Set workflow parameters
workflowAssociation.AllowManual = true;
workflowAssociation.AutoStartCreate = false;
workflowAssociation.AutoStartChange = false;
// Add workflow association to my list
ctType.WorkflowAssociations.Add(workflowAssociation);
// Enable workflow
workflowAssociation.Enabled = true;
}
catch(Exception exception)
{
SharePointLogger.Local.TraceToDeveloper(exception, exception.Message);
}
finally
{
web.AllowUnsafeUpdates = false;
}
}
}

}

No comments:

Post a Comment