SPD Workflow – Approval Task Email Notification with link to Edit Task Form

Posted By Posted by: Irfan Rizvi on August 10, 2017

We recently received a request from a customer relating to their governance workflow, in this case, the SPD Project Server 2013 workflow. When an approval task is assigned to a user, the customer wants a generated user email notification with a link to the task’s edit form instead of the display form (the default behaviour).

This seemed like a very simple request and I thought I’d be able to make it happen in 10-15 minutes. On the contrary, it turned out to be quite tricky. I’ll take you through my various attempts at this request and how I finally achieved it.

My first attempt was to form an Edit form’s URL in a variable and for each Assign Task email, I will append it with the Task ID. However, the Task ID was not available at the time of the email creation and is only populated after the Assign Task action is completed.

The second attempt then was to skip the email notification in Assign Task and try to send the email using a Send Email action. However, the Assign Task action holds the workflow until completion, hence the email will not be sent until the task is completed which negates the purpose of the email notification.

At this point, I concluded this might have to be resolved outside SPD’s limited boundaries and use the mighty power of JavaScript, so here’s what I did:

In the email notification, where the task link was set, I appended a redirect parameter in the query string.

Then, I added the following JavaScript on the DispForm.aspx page of my task list:

 function getRedirectMode() {
        var redirectMode = "";        
        var URL = window.location.search.substring(1);        
        var MyArray = URL.split("&");
        for (i = 0; i < MyArray.length; i++) {            
           MyParameter = MyArray[i].split("=");            
           if (MyParameter[0].toLowerCase() == "redirect") { 
               redirectMode = MyParameter[1]; 
               break;            
           }        
        }        
        return redirectMode;    
} 

function checkRedirection(){ 
     if(getRedirectMode().toLowerCase() === "yes"){ 
         var url = window.location.href.replace("DispForm","EditForm"); 
         window.location.replace(url); 
      } 
 } 

_spBodyOnLoadFunctionNames.push("checkRedirection");

This script redirected the user to the Edit Form page when it finds the redirect parameter in the query string.

Javascript was my hero again, long live JavaScript.


Blog Posted In Blog Posted In: Blog, How to, Project Server
Blog Posted In