Simple Document Sign Off - Part 7 - Sign Off Workflow

Introduction

The sign off workflow processes sign off records and completes the following tasks:
  1. Populate Document Name and Document Version fields in sign off record.
  2. Generate Document Link and assign it to sign off record.
  3. Either creates a new record for the first sign off on a document, or updates an existing record if this is a subsequent sign off on an existing document.
  4. Delete redundant records (sign offs for documents that have already been signed off on, same version
The workflow effectively ensures there is only ever one sign off record for each document for each person (rather than multiple sign off records for the same document with the same version).

Technical Summary

If you are an advanced SharePoint workflow configurator, then you may be able to create the workflow from the technical summary below. If not, detailed instructions follow and this serves as a good overview.


Workflow Name: Document Sign Off Processing
Start Options: Start workflow when an item is created (enable manual starting for testing).
Associated List: Document_Sign_Off

LineAction
1Assigns the variable documentID to the value in the current item sign off record document ID.
2Assigns the variable documentName to the value of the document name from the document library cross referenced by ID.
3Assigns the variable documentVersion to document version from the document library cross referenced by ID. Uses built in Version field associated with document library, not added field.
4Creates the variable document link by concatenating the link to the sign off page and the document ID.
5KEY STEP. Assigns variable ExistingDocumentVersion to the version of the EXISTING sign of record for this document in the sign off library (if it exists). This step goes to the sign off list and sees if there is already a record with this documents ID. If there is, then it extracts the version, and it is assigned to this variable. If there isn’t, the variable remains at its default value, 0.
6Condition 1. If ExistingDocumentVersion is 0, then no sign off record for this user for this document yet exists.
7Condition Action. Since no document sign off yet exists, create one and update the fields in the sign off record, document link, document name, document version.
8Condition 2. We now know from condition 1 that the document version for this sign off record has a value. If this value is not equal to the version of our current sign off record, then:
9Condition Action: replace the version on the EXISTING sign off record with the updated version from the NEW sign off record.
10Condition Action: Then delete the NEW sign off record.
11Condition 3. If the current sign off record document version is equal to the existing sign off record version, it is redundant:
12Condition Action: Delete it.

Sign Off Processing Workflow, Step by Step


Create workflow Variables

I like creating workflow variables as intermediate containers for values I use in the workflow. This give me two advantages:
  1. I can easily sent a test email with these values embedded to see if they are being assigned correctly.
  2. The workflows functionality is more obvious upon observation.

With that in mind, create the following workflow variables:
  1. DocumentID(number)
  2. DocumentVersion(number)
  3. DocumentName(string)
  4. DocumentLink(string)


Set the Document ID


The document ID is the simplest value to set, set the variable documentID to the current items Document ID:



Set Document Name and Version


The next two variable are set by extracting the values from the document library using the document ID. Here is how you set that up:

After choosing your "Set Variable Name" action and choosing your workflow variable, click the "value" link and the "fx" button and the workflow lookup dialog opens. Change the data source to your documents library, mine is called "Documents". In "Field from source" choose your document "Name". In the "Find the list item" section, for "Field", select "WorkflowSetID". Then click the "Fx" button beside the "Value" field, choose "Workflow Variables and Parameters" for data source, and select "Variable:Document ID". The lookup should now look like this:


Repeat this process for the document version variable, selecting "Version" as field from source this time, all other components set up the same.

Generate Document Link

The document link is the field we use in the sign off record that points us right back to the document that was signed off on. This is useful in the sign off record as it allows users to quickly locate documents they have signed off on. This link is generated and then assigned to the DocumentLink variable. Click the "value" link beside the variable setting action, and click the three dots beside that link (NOT the "Fx" button). Copy the URL to your document library, mine is:

https://sp13build.viha.ca/sites/ePaydev/DocSignOff/Shared%20Documents/Forms/AllItems.aspx

Remove the trailing information so your link now looks like this:

https://sp13build.viha.ca/sites/ePaydev/DocSignOff/Shared%20Documents/

Now place your cursor at the end of the link, and click the "Add Change or Lookup" button, and select your workflow variable "DocumentName". Then add ".docx" to the end of the string so that your string ends up looking like this:


Extract EXISTING document version

This next KEY STEP goes to the sign off library and checks to see if a sign off record for this document already exists. If it does, then it extracts the version and assigns it to the ExistingDocumentVersion variable. This is done by:

  1. First select your variable existing document version for your "Set Workflow Variable" action.
  2. Click the "value" link beside this field, and click "Fx".
  3. For "Data Source" choose your SIGN OFF LIST called "Document_Sign_Off". For field from source, choose "Document_Version".
  4. In the "Find the list item" section, select field "DocumentID".
  5. In the "Find the list item" section, click the "Fx" button beside the "Value" field.
  6. In the lookup dialog, change "Current Item" to "Workflow variables and parameters".
  7. in the lookup doalog, click "Field from source" and select "Variable:DocumentID".
  8. Click OK. Your lookup should now look like this:



You may notice that we are not doing any comparisons to find out WHO created the record. That is, we are going to the sign off library and getting records based on document id, but we are not considering WHO this is (their identity). This is because this is AUTOMATICALLY taken care due to the permissions on the document sign off list. This list only allows users to view and edit their own records. The workflow follows these permissions, and will only extract records that the current user created. So we don't have to filter for user.

Condition 1 - No sign off record yet exists


The first test we complete is to determine if a sign off record already exists for this user and document. If the variable ExistingDocumentVersion is 0, it is at its default value, no other sign off records exist for this document. So set up your condition as follows:


Then for the action that follows this condition, choose "Update List Item". Now click the "this list" link and leave the choice as "Current Item". Click the "Add" button and select "Document_Name" for the field, and select "workflow variables and parameters" for data source, and select "DocumentName" for the "Field from source". Your step should now look like this:


Repeat this process for Document Link and Document Version. When done your "Update List Item" dialog should look like this:


Condition 2 - a sign off record exists but its version is different


Set up your condition the same way you set up the last one, testing against existing document version. However, in this test, we are not comparing to 0, we are comparing to the extracted version since we now know it exists. Your condition should look like this:


Since we know a sign off record exists, we don't need to go through the steps of updating the document name and link because that has already been done. However, the document version is different so we want to update the existing record with the updated version and delete this new record. So our first step is to update the sign off record. Select "Update List Item" for your action, click the "this list" link, and select your document sign off library (Document_Sign_Off). Click "Add" and set the "Document_Version" field to the workflow variable "ExistingDocumentVersion". In the bottom of the "Update List Item" dialog select "DocumentID" for the field, and select your workflow variable "DocumentID" for the value. Your update list item dialog should look like this:


Finally, delete the current record as it is now no longer needed:


Condition 3 - sign off record exists with same version as this one


If the extracted document version is equal to the sign off record document version, then this is a duplicate sign off. Delete it:

Testing

Test this workflow by going to your sign off library, locating an existing record, and start the sign off workflow it manually. Ensure the name and link fields are populated correctly. Now start from the beginning, trigger a sign off notification from a document, click the link in the email and register your sign off, and see if the sign off record then exists in the sign off list. If it does, ensure it is being updated with name and link.

Now test the more complex features. Resign off on the same document (simple click the sign off link in the workflow email again). Register your sign off and see what happens. As this is a duplicate sign off, it should be deleted leaving the original sign off record.

Now test the version update components. Go back to the original document library and make an update to the document or its metadata to update its version. Then trigger the sign off process and complete a sign off. If this system is working at it should, you should see ONE sign off record for this document in the sign off library with the latest version recorded.

Note for admins


This system works in conjunction with the permissions on the sign off library, preventing users from accessing other users records. This allows a simpler workflow because we do not have to explicitly compare who created the records. This also does mean that ADMIN LEVEL USERS WILL EXPERIENCE NON_STANDARD FUNCTIONALITY when using this system in production. A single admin user can test functionality on this system and it will work as needed. So first test this way. However, once multiple users start signing off on documents, admin level users are no longer able to use the system. Testing should be done with a user account that does not have admin level permissions to ensure everything is set up right. This is standard practice for a system like this as we want to be able to ensure regular users, not admin users, can use this system.

So, first test and get the system working as an admin user. Then, once completed, test the system again with a regular user to confirm permissions and functionality.

<- Simple Document Sign Off - Part 6 - Notification Workflow

Simple Document Sign Off - Part 8 - Managing Document Sign Off ->

No comments:

Post a Comment