Frage

Here is the scenario:

I have created a custom list definition in Visual Studio 2015, and I'm packaging it in a Site scoped feature (Farm solution). I have also created an event receiver that will automatically be attached to any new list instances created from this definition based on my custom list template ID.

I need to do something similar with a workflow. That is, I need to create a 2013 workflow and package it in the feature in VS so that it will automatically get deployed with the feature, and will automatically attach to any list instances created from the list definition.

I would prefer to create the workflow directly in VS, but I'm not sure of the right way to go about doing that, since the only options are List workflow and Site workflow. Site workflow is not appropriate because I need to do work on list items. List workflow is ultimately right, but you have to specify an existing list instance that it will get attached to.

I have read that Reusable workflows can be associated with a content type, and thus might work, since I am using a custom content type with this list definition, but apparently Reusable workflows can only be created in Designer.

What are my options here?

I am on-prem, and already have a List Added event receiver, so if I need to do some kind of wiring-up of a workflow template to a list instance after it is created, I can work with that.

War es hilfreich?

Lösung

Turns out to be easier than I expected, although there is no automatic association through content type or list template ID.

Basically, you just create a List workflow, but do not associate it with a list. Associating a List workflow with an existing list is optional in VisualStudio.

As stated in the question, I am on-prem and able to take advantage of event receivers, and I did have a List Added receiver already, so I just added more code to that to create the workflow subscriptions for the newly created list.

To do that I followed that basic outline in this answer:

https://sharepoint.stackexchange.com/a/143582/8992

Now anytime someone creates a new list based on my custom definition, the workflows get automatically wired up.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top