1

I am creating a workflow which I want users of certain sites in a site collection to be able to use.

When they activate the feature, the workflow should be created and automatically get attached to the "Documents" library.

So I create a workflow, and I uncheck the box that says "Yes, associate this workflow with the following libraries and lists. If this step is omitted, you must manually associate the workflow after it is created".

So far so good.

I have the workflow in one feature. The task- and history list in another feature. The last feature contains an eventreceiver with the following code:

    var taskList = web.Lists.TryGetList("WorkflowTaskList");
    var historyList = web.Lists.TryGetList("WorkflowHistoryList");
    var associationList = web.Lists.TryGetList("Dokumenter");

    if (taskList != null && historyList != null && associationList != null)
    {
            SPWorkflowTemplate wflTemplate = web.WorkflowTemplates.GetTemplateByName("WFName", System.Globalization.CultureInfo.CurrentCulture);

                SPWorkflowAssociation wflAss = SPWorkflowAssociation.CreateListAssociation(wflTemplate, "WFName", taskList, historyList);

                wflAss.AutoStartChange = false;

                wflAss.AutoStartCreate = false;

                wflAss.AllowManual = true;

                web.AllowUnsafeUpdates = true;

                associationList.AddWorkflowAssociation(wflAss);

                associationList.Update();

                web.AllowUnsafeUpdates = false;
    }
    else {
            return;
    }

This is the code that is supposed to associate the workflow with the document library. The problem is that it does not find a template with the name "WFName".

If, however, I go to the documents library in SP, and create a new workflow manually, I am able to select WFName as a template. All the other templates available are 2010 templates.

Does anyone know why I can't find my template? I can't find the template using Powershell either. It's only visible in the SP gui

Oh, and by the way. This is a 2013 on premise farm solution. The workflow manager is installed and seems to be working as intended.

Thanks.

Your Answer

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

Browse other questions tagged or ask your own question.