Author | Palesa Sikwane |
Long Description | Do you need to scan through a SharePoint Sites contents and apply some logic based on the existence of a content type? Or maybe even go as far as scheduling this? Then this post is for you! |
Dependencies |
**And the applicable SharePoint® version for the Nintex® Workflow versions above. |
Support Info | |
Additional Information | N/A |
Product used | Nintex® Workflow 2016 | Version: 4.2.0.10 - International |
Greetings from a warm and sunny side of Johannesburg, South Africa! It's finally Spring time in this side of the world!
First things first, I would like to thank Michelle Barker for coming up with this question and requirement!
As you guys would know, reusable workflows have the following properties:
- Are associated with SharePoint® Content Types
- Because they are linked to a content type, they can be made available wherever those content types are used in a site collection
Some of the advantages of using a reusable workflow are:
- Having one Central place to make changes and publish a workflow and push it down to every list or document library
- Making use of site templates that have content types with workflows linked to them
Some of the disadvantages of reusable workflow:
- Inability to schedule a reusable workflow out of the box
- Cannot be tied to a site workflow meaning that you cannot really schedule it using a site workflow.
What if then you were faced with a requirement that needs you to run a scheduled workflow based on a content type which could span across different lists and libraries? Maybe you have a requirement to send out reminder(s) at a certain frequency for certain document types?
How would you go about it?
Well there is a way that involves:
1. Finding all of your lists on your site
2. Getting all linked content types for each list
3. Per content type, Switch and apply your logic.
I built this using the following site workflow:
Step # | Workflow Action | Description |
---|---|---|
1. | Call web service action (Get List Collection - Internal Names) |
Note: I've configured this to actually return the InternalName of my lists or the GUIDs in a collection variable called ListCollection. You will see how and where we use this later... |
2. | Collection Operation | Here I simply count how many lists are in my collection and store this in a variable called No Lists:
|
3. | For Each | This is my first For Each where I basically loop through my ListCollection I retrieved in Step 1, and store the InternalName or the GUID of each list in a variable called ListGUID. The configuration is as follows:
|
3.1 | Here I basically log the current lists index in my collection(ListCollection) as well as the ListGUID: | |
3.2 | Call web service (Get List Content Types) | Next, I call another SharePoint Web Service called GetListContentTypes based on the current ListGUID that my For Each in Step 3 is looking at.
I then store the results in a collection variable called List Content Types. This step is configured as follows:
Note: The results returned here are in XML, and one of the NODES in the XML contain the Name of the content type, which is what we want |
3.3 | Seen that in Step 3.2 I get returned some XML, I simply query the XML in this step to get the Display Name of my content types and store these in a collection variable called Content Type Names. I've configured this step as follows: | |
4 | This is my second For Each; which allows me to iterate through each content types name stored in my collection Content Type Names: | |
4.1 | Here I simply log the name of my content type: | |
4.2 | Switch (per content type) | Note that I haven't put this in my workflow, but this is where the magic happens for you guys.
So because we've found content types for any list or library across our site with the previous steps, we can use a conditional action such as a Switch to put in some workflow logic as required per content type! |
Running this workflow will give you the following result in your workflow history:
So as you can see my Workflow scans the current site, and for each list and library returns the associated content types.
Feel free to download this and play around with it, and do what you will with it Maybe even make it a User Defined Action?
Let us know how you guys used this!
I hope this helps someone out there!
Cheers