Very often different forms contain parts, which should be filled in by different persons, for example by employee and supervisor. In such cases, it is good idea to have not only approval workflow running on incoming form, but also to hide supervisor’s section for the original form creator. Using following technics company can avoid spare information and potential mistakes.

Here is the case. Employee (James Sullivan) creates and fills in the “Personal statement” form in the SharePoint. Once he submits the form, approval workflow starts automatically. Workflow sends notification to James’ supervisor (John Smith). John receives notification mail with form attached and can preview it directly in the mailbox. Direct link to the form is also available. Supervisor is able to open the form, put his own comments on employee statement and then go to his tasks and approve or reject the form. All the known information, such as employee and supervisor’s names, is prepopulated automatically.

On each workflow stage, form will lock or open sections for each user. While form is new, supervisor’s section is not visible and is not accessibly by the user. When supervisor opens the form, user’s section is made read only and could not be edited. When form is rejected or approved, all the fields are locked for editing. Same time special field inside the form is displaying current workflow status.

Step by step intro

Employee creates new form. His name (James Sullivan) and email are prepopulated from the SharePoint user list. User submits the form.

PDF Share Forms 1 Create formPDF Share Forms 2 Submit-form
Once form is submitted, form data is synchronized with SharePoint columns and workflow starts automatically and sends notification and form attached to supervisor — John Smith.

PDF Share Forms 3 Form-Sync
Supervisor can review the form directly in his mailbox and click on the link to open form.

PDF Share Forms 4 NotificationPDF Share Forms 5 Form Preview

When supervisor opens form, his section becomes available, user part is locked. Supervisor’s name and last name are prepopulated.

PDF Share Forms 6 Supervisor comment

After supervisor has put all his comments and submitted the form, he can Approve or Reject the form by opening task in the Task list.

Workflow task

When workflow is finished, form locks.

PDF Share Forms 7 Form Locked

The code

While SharePoint controls workflow status natively, PDF forms require some additional coding to have workflow status displayed in the form itself. In our case we’ve used server side C# code triggered on form open. Each time user opens the form, code starts and checks workflow status and updates special form field. Same code is responsible for prepopulating form fields with current user data.

if (form.IsNew())
{
    data.resolveNode("Name").value = 
        currentWeb.CurrentUser.Name.Split(' ')[0];
    data.resolveNode("Last Name").value = 
        currentWeb.CurrentUser.Name.Split(' ')[1];
    data.resolveNode("email").value = 
        currentWeb.CurrentUser.Email.ToString();
}
if (!form.IsNew())
{   
    SPFile file = currentWeb.GetFile(form.DocumentID);
    SPListItem item = file.Item;                         
    SPList list = item.ParentList;

    string workflowField = "ApprovalWF";

    SPFieldWorkflowStatus statusField =                              
                  list.Fields.GetField(workflowField) as SPFieldWorkflowStatus;                 
    object value = item[workflowField];                               
    data.resolveNode("Status").value = "Approval: " + statusField.GetFieldValueAsText(value); 

    if (data.resolveNode("Status").value == "Approval: In Progress")
    {
        data.resolveNode("Supervisor Name").value = 
            currentWeb.CurrentUser.Name.Split(' ')[0];
        data.resolveNode("Supervisor Last Name").value = 
            currentWeb.CurrentUser.Name.Split(' ')[1];
    }
}

Another code — JavaScript — is used on client side to lock or unlock different form parts using current workflow status.

var status = this.getField("Status").value;
if (status != "") {
    this.getField("Name").readonly = true;
    this.getField("Last Name").readonly = true;
    this.getField("email").readonly = true;
    this.getField("Statement").readonly = true;

    this.getField("Supervisor label").hidden = false;
    this.getField("Supervisor Name label").hidden = false;
    this.getField("Supervisor Last Name label").hidden = false;
    this.getField("Supervisor Name").hidden = false;
    this.getField("Supervisor Last Name").hidden = false;
    this.getField("Supervisor Comments").hidden = false;
    this.getField("Supervisor Comments label").hidden = false;

    this.getField('SubmitButton1').hidden = true;
    this.getField('SubmitButton2').hidden = false;
}
if (status == "Approval: Approved" || status == "Approval: Rejected") {
    this.getField("Supervisor label").readonly = true;
    this.getField("Supervisor Name label").readonly = true;
    this.getField("Supervisor Last Name label").readonly = true;
    this.getField("Supervisor Name").readonly = true;
    this.getField("Supervisor Last Name").readonly = true;
    this.getField("Supervisor Comments").readonly = true;
    this.getField("Supervisor Comments label").readonly = true;

    this.getField('SubmitButton2').hidden = true;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.