SharePoint: How to Create an Auto-Incrementing Number Field For Use in a Custom ID – Part 2

In the last article, we built our "Auto ID Master" list that will contain our auto-incrementing number, and our "Project Library" where we’ll be uploading project documents that will have the workflow applied.

This time, we’re going to start building out our workflow that will increment our “Next Number Available” value and build our custom “Project ID”.

And again, DO NOT CREATE ANY ITEMS ON THE LIST, OR ADD ANY DOCUMENTS TO THE LIBRARY YET!!!!! wait until the end of the series where we test things.

Getting Started

In order for us to be able to have the workflow start when a new item is created, we need to actually create two separate workflows and start them at different times depending on the "state" of the document. The reasoning behind this is as follows:

In a list, when you create a new item, you’re filling in all of its details before the item is actually created. When you save it, all of its details are available immediately. On a document library however, adding a new document to the library is actually a 2-part process:

  1. Adding it to the library first
  2. And then filling in its details second

Because of this, using a workflow that is set to start when a new item is created will only have access to any existing metadata that was already part of the document. Anything new or custom that you want to add in will only be available AFTER you have uploaded it then accessed its “Edit” page, filled them in and saved.

What we’re going to do is create an "Initializer" workflow that will update the details of the document once we’ve filled in all of its information on the "Edit" page, thereby allowing a second workflow to run that will have access to all of the details needed.

So for our first workflow, we’ll only need to set up a few things, but after its completed, the second workflow that will perform the bulk of our steps will have access to all the details of the uploaded document and be able to do what’s needed for our scenario.

To make this work better, and to allow us to make changes to documents later without accidentally firing off the workflow when it’s not needed, we need to go back to our "Projects Library" and create one final column that both of our workflows will use to determine if the workflow is to start or not.

In the "Projects Library" create a new column called "Run Main Workflow", make it a "Choice" type and enter in the following choices:

Yes
No

Also, to make it easier to understand the point of the column when viewing it on the "Edit" form, add in the following description:

"This column should only have a "Yes" value when the document has first been uploaded (set this manually).

All other times, the value should be "No" in order to prevent the workflow from running again."

Set its default value to "No" and click "OK" to add it to the list.


Once created, we can now move back to SharePoint Designer to build the workflows.

To start, open SharePoint Designer and connect to our site.

Once connected to our site in SPD, create a new workflow.

Name the workflow "Initialize Workflows", attach it to the "Projects Library" and set its start options to "Automatically start this workflow when a new item is created".


Click "Next" to move to the next screen for specifying the workflow steps details.

NOTE – in any of the remaining steps, when I mention choosing a particular option from the “Actions” menu and you don’t immediately see the option available, choose “More Actions” at the bottom of the list to see all available actions.

Under the "Conditions" menu, select "Compare Projects Library Field".


Click the "field" link and choose "Run Main Workflow" from the dropdown list then click the "Value" link and choose "No" from the dropdown list.


With this set as our condition to check for, the workflow will only run if the value of the "Run Main Workflow" field is set to "No"…which is what we have set for its default value, so the workflow will start as expected.

Next, under "Actions", select "Wait for field change in current item".


Click the "field" link and choose "Run Main Workflow" from the dropdown then click the "value" link and choose "Yes" from the dropdown.


Next, under "Actions" select "Update List Item".


Click the "this list" link to open the "Update List Item" screen.


Click the "Add" button, and in the "Value Assignment" window that opens, choose "Auto Number" in the "Set this field" dropdown and then type in "xxxx" in the "To this value" field then click "OK" to close the "Value Assignment" window.


NOTE – "xxxx" is just an arbitrary value and is just used as a means to update the item. The second workflow will be updating this field later to change this temporary value .


Click "OK" to close the "Update List Item" screen and return to the main workflow designer screen.


With this, the first workflow is now completed. Click the "Finish" button to build and attach the workflow to our "Projects Library".

What this workflow accomplishes is to allow for us to have a workflow that on item creation, will wait until we’re ready for it, then run and setup what we need for our next workflow to be able to run. It simply waits until we update the "Run Main Workflow" field (which we do immediately after uploading the document and filling in its form details), then performs an update which will initiate the run of the second workflow (we’ll be setting it to start on item change).

In the next article, we’ll continue on by building out our main "Update ID" workflow.

source:endusersharepoint.com

0 nhận xét:

Post a Comment

thanks comment