views:

25

answers:

1

I'm just starting to use sharepoint designer and realised there's a lot that can be done to extend the basic features in sharepoint. We have an email alert sent out when a new task is created (by the user) and I want to customise the email so that it also includes a link called 'Assign'. When clicked, I want this link to automatically update the task with the assigned to field for the person that clicked it.

So I think the way to do this would be to hard-code the assign to value in the url behind this link, but I have no idea if this is possible or if there is an easier/better way to do this.

Any advice would be appreciated as I'm a complete beginner.

thanks.

+1  A: 

I will not cover "How to modify the contents of an eamil alert" here as that is a seperate question and there are a lot of articles that cover that already.

For the Assigned link :-

You would need to create a custom page (or web part on an existing page) as the destination of your Assign link - this would take the Task ID as a query string param and then update the assigned to with the current user.

You could make this flexible by also taking the ListID but you may want to think about how this could be abused and put appropriate measures in place.

EDIT - in response to comment.

This is top of my head, not checked in compiler. This would have to sit on the same server as SharePoint to work as its using the OM - if you want to use a different server (why would you though) then look in the web services.

private void updateAssignedTo(Guid listId, int itemID)
{
   SPWeb web = SPContent.Current.Web();
   SPList list = web.Lists[listId];
   SPListItem item = list.GetItemById(itemID);
   item["Assigned To"] = web.CurrentUser;
   item.Update();
}

You're going to have to work out how to get this code into to page or web part (SharePoint Designer is not going to cut it I think, you need Visual Studio) but its a starting point.

Ryan
This sounds exactly what I'm after. I like the idea of a custom page with a query string param, but when you say 'update the assigned value' how would I do this please? thanks for you help.
HAdes
Updating data from an HTTP GET statement, as will be the case with a custom page and query string, will leave you subject to Cross-Site Request Forgery attacks. Consider the risks before proceeding with an implementation.Now, you can avoid the security risk by requiring the user to click an OK button on the custom page, which will cause the update to occur on an HTTP POST.
kbrimington
Good code snippet. Note that if the code is processing in a GET, you will need to allow unsafe updates. See http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.allowunsafeupdates.aspx.
kbrimington