SharePoint User Group UK

Share the knowledge!

Welcome to SharePoint User Group UK Sign in | Join | Help
in
Home Blogs Forums Photos Files Roller

Task URL in workflows..

Last post 05-16-2008, 10:22 AM by Cimares. 23 replies.
Page 1 of 2 (24 items)   1 2 Next >
Sort Posts: Previous Next
  •  08-21-2007, 8:14 PM 4978

    Task URL in workflows..

    I've decided to replace the standard Task e-mails within my workflow with my own custom ones. This is mainly due to the way we're going to be notifying groups of pending tasks.

    What I need to do is include a link directly to the task that is being raised within the HTML of the e-mail.

    But it's been a long day and I thought I'd post this before going home and sleeping on the problem in case one of you has done this before.. Why re-invent the wheel?..grin

    ctProjects.TaskProperties has been created with the CreateTask activity, but I can't for the life of me find an entry in this that will give me the url. I'm guessing I'm going to need the .TaskItemId and use it against something from the workflowProperties that returns the Task list, however this taskitemId returns -1 when passed through ToString().

    Any ideas welcomed to point me in the right direction.

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  08-22-2007, 3:49 PM 5001 in reply to 4978

    Re: Task URL in workflows..

    Found the solution, and I call it from the follwing line of code within each of the 12 parallel tasks that may or may not need the Url. This returns a properly formatted <A> link for insertion into a e-mail.

    string taskurl = returnTaskUrls(ctProjects.ListItemId.ToString());

            private string returnTaskUrls(string taskId)
            {
                //Use this to return the relevant URL's for use in e-mail of tasks.
                string weburl = workflowProperties.WebUrl;
                string taskUrl = "/_layouts/WrkTaskIP.aspx?List=";
                string listId = workflowProperties.TaskListId.ToString();
                string fulltaskUrl = weburl + taskUrl + listId + "&ID=" + taskId;
                string htmlTaskLink = "<a href=" + "\"" + fulltaskUrl + "\"" + ">Click here to open the task directly in SharePoint</A>";

                return htmlTaskLink;
            }


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  08-29-2007, 2:16 AM 5071 in reply to 5001

    Re: Task URL in workflows..

    Hi Cimares,

    Thanks for your post. I'm new to Sharepoint and I encounter the same problem. Would you please explain how to get "taskid"? What's "ctProjects" in your code?

    Thanks a lot.

    Sean

  •  08-30-2007, 4:41 PM 5117 in reply to 5071

    Re: Task URL in workflows..

    Hi Sean,

    Ok, the ctProjects is the name that i gave to that instance of the Create Task object that I dropped onto the workflow.

    ctproject.ListItemId gives you the task ID that the task has been assigned by SharePoint. To see this for yourself, connect to a sharepoint list and open a workflow task form from the task list.

    The URL will look similar to: http://webserver/_layouts/WrkTaskIP.aspx?List=b0320c4f%2Df791%2D4a9c%2D9b6f%2D3f1eef448fe5&ID=1

    What my code does is grab the relevant parts of this url from the various objects in the workflow and then re-builds it for inclusion in the task e-mail.

                string weburl = workflowProperties.WebUrl;            webserver
                string taskUrl = "/_layouts/WrkTaskIP.aspx?List=";    /_layouts/WrkTaskIP.aspx?List=
                string listId = workflowProperties.TaskListId.ToString();       b0320c4f%2Df791%2D4a9c%2D9b6f%2D3f1eef448fe5

    The final line then rebuilds the url which is then wrapped in a standard hyperlink with http:// tacked on the front.
                string fulltaskUrl = weburl + taskUrl + listId + "&ID=" + taskId
                string htmlTaskLink = "<a href=" + "\"" + fulltaskUrl + "\"" + ">Click here to open the task directly in SharePoint</A>"

    The other main object you're looking at here is workflowProperties. This is initialised as part of the onWorkflowActivated icon at the top of your workflow designer view and references things like the Guid of the Tasklist and the URL of the webserver hosting the workflow.

    If you're going to be doing much with workflows, then I'd recommend that you try a book by David Mann, Workflow in the 2007 Microsoft Office System - Apress books. It's not the answer to all your prayers, but it's certainly a damn good start!

    Regards

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  09-05-2007, 12:32 PM 5263 in reply to 5117

    Re: Task URL in workflows..

    Hi

    I was hoping to use the out of the box approval workflow as an initial 'basic' workflow in our system.  The only problem is the link to the document doesn't include the server, ie the source of the email would be something like, /pages/default.aspx.  Do you know if there is any way to customise this one piece of data rather than having to write a totally new custom workflow?

    Thanks
    Andy

  •  09-05-2007, 2:08 PM 5265 in reply to 5263

    Re: Task URL in workflows..

    Alas I don't think so. From what I've seen, the only way to access the web URL is through workflowProperties.WebUrl and this wouldn't be available to you in the OOTB workflows. You might be able to access this information from within SharePoint designer to avoid doing a full custom workflow, but I'm not sure as my only experience is using VS2005 workflows.
    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  10-18-2007, 3:37 PM 6226 in reply to 5117

    Re: Task URL in workflows..

    Dear Paul,

    I have used your code inside CreateTask1method 

    returnTaskUrls(CallExternalMethod_CreateTask1.ListItemId.ToString());            

    Where CallExternalMethod_CreateTask1 is the name used in the designer and is calling method createtaske1 the problem is that CallExternalMethod_CreateTask1.ListItemId=-1. Can you please advice how to solve this problem because every other report i could find are speaking about the same problem and the only solution is to use it inside change even of task1 (which means after the event (aprove/reject) has run )

     

  •  10-24-2007, 12:43 PM 6329 in reply to 6226

    Re: Task URL in workflows..

    So far I've implemented a custom state machine workflow with infopath forms. The examples of "StateMachineApprovalWorkflow" given by Microsoft was very helpful in understanding the concepts.

    The afterproperties and beforeproperties of task onchange event activity are important ones to collect the values of external properties.

    Feel free to post queries...
  •  10-26-2007, 11:13 AM 6399 in reply to 6226

    Re: Task URL in workflows..

    Hiya gchalk,

    Where CallExternalMethod_CreateTask1 is the name used in the designer and is calling method createtaske1 the problem is that CallExternalMethod_CreateTask1.ListItemId=-1.

    If you're getting -1 being passed to the method, then you're not returning a valid task listitemid. You need to be seeing a positive interger value that represents the task list assigned to the workflow.

    I'm not familiar with the CallExternalMethod function, so not sure why you're using it, In my workflow, I just use my name instead of  CreateTask1.ListItemId.ToString(). If you're calling this from within the CreateTask1 method, then you should be able to address the ListItemId directly like this, rather than calling via the external method.

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  10-26-2007, 12:51 PM 6404 in reply to 5263

    Re: Task URL in workflows..

    spdevlondon - you can use SharePoint designer to create a workflow which is a middle way between the OOB workflows and writing something from scratch using WWF.

    The syntax for this can be found here http://www.aidangarnish.net/blog/post/2007/08/MOSS-2007-Workflow---link-to-current-item-in-email.aspx

    If you can't be bothered to visit my blog then this is how to add a link to the current item to the body of your email:

    <a href="http://[serverName]/sites/[siteName]/Lists/[listName]/DispForm.aspx?ID=[%[listName]:ID%]">Link to item</a> 


    http://aidangarnish.net/blog
  •  02-26-2008, 2:29 PM 8669 in reply to 5117

    Re: Task URL in workflows..

    Hi, i'm having problems to get the id of the task.

    I have a create task activity (createTaskTicketToPrimary.) inside a while, in the method invoking of the task i am doing this:

    createTaskTicketToPrimary.ListItemId to get the task id to put in my link but i am getting -1!!

    I have other tasks and on these task this is working but for this particular case (create task inside a while) i'm getting -1 any suggestions??

    Thanks

  •  02-26-2008, 3:56 PM 8681 in reply to 8669

    Re: Task URL in workflows..

    Hi javieruy,

    Can you post the code that's returning the -1 and just explain where in the lifecycle of the task you're returning the id?

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  02-26-2008, 4:06 PM 8684 in reply to 8681

    Re: Task URL in workflows..

    Here is the code:

    private void createTaskTicketToPrimaryMethodInvoking(object sender, EventArgs e)

    {

    createTaskTicketToPrimary_TaskId1 = Guid.NewGuid();

    listItemId = createTaskTicketToPrimary.ListItemId; //Here i have the -1

    createTaskTicketToPrimary_TaskProperties1.AssignedTo = "someuser";

    createTaskTicketToPrimary_TaskProperties1.Title = "Primary Ticket";

    createTaskTicketToPrimary_TaskProperties1.Description = "Description"

    createTaskTicketToPrimary_TaskProperties1.SendEmailNotification = false;

    createTaskTicketToPrimary_TaskProperties1.TaskType = 2;

    }

     

    This create task activity is inside a while. the listItemId is a global variable...

    I have did before on other activities and it worked the problem seems to be the while, for some reason the listitemid is not been binded.

     

  •  02-26-2008, 4:28 PM 8685 in reply to 8684

    Re: Task URL in workflows..

    Whats the purpose of the while loop in your code? In all of my workflows the task creations has sat outside of the while loop, with the onTaskChanged and the UpdateTask within a while loop waiting on an end condition.

    I think the while loop might be interfering with the creation of the task, hence the ListItemID is blank when you try and call on it.

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  02-26-2008, 5:04 PM 8687 in reply to 8685

    Re: Task URL in workflows..

    I'm putting the createtask activity inside the while becuase the log of the business is:

    I have to create a task to a user, the user approves the task, and then i create another task to the supervisor and  he can say the user task is wrong and then the task to the user must be created again.

    So i put all these inside a while, while the supervisor rejects the user task i create the task again for the user.

    If i don't use a while what else i can do there?

     

Page 1 of 2 (24 items)   1 2 Next >
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems