Retrieving a User's Task List?

Aug 8, 2013 at 2:22 AM
Hi,

First off, let me just say that spservices is an amazing resource.

Question: are there any examples out there of using spservices as a method to retrieve the current user's tasks?

I currently have this functionality using a slightly customized web part (thanks to this great article), but I'd really prefer to do it in spservices. Any suggestions?

Cheers,
Carl
Coordinator
Aug 8, 2013 at 3:29 PM
Carl:

If it's just a single list, then it would be a simple GetListItems with the proper filtering. If you're looking across the site (or wider), then a call to the Search service probably makes sense.

M.
Aug 8, 2013 at 9:33 PM
Edited Aug 8, 2013 at 9:34 PM
Hi Marc,

Thank you for the help! I think I'm getting there, but I am a bit of a novice programmer and am receiving results that are not just for one user. Do you see anything (or several things) in the code below that look ill-advised?

Thanks again!
function getMyTasks() {

// Get Current User
var myUserName= $().SPServices.SPGetCurrentUser({
    fieldName: "UserName"
});

//alert(myUserName)

// Create Search for Tasks
 var queryText = "<QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'>"
    queryText += "<Query>"
    queryText += "<Context>"
    queryText += "<QueryText language='en-US' type='STRING'>"
    queryText += "ContentClass:\"STS_Site\" ContentClass:\"STS_ListItem_Tasks  AssignedTo:" + myUserName + "*\"";
    queryText += "</QueryText>"
    queryText += "</Context>"
    queryText += "</Query>"
    queryText += "</QueryPacket>";

$().SPServices({
    operation: "Query",
    queryXml: queryText,
    completefunc: function (xData, Status) {
        alert("Status: " + Status);
        $(xData.responseXML).find("QueryResult").each(function() {
                    // What are my results?
                    $("#myTasksTemp").append($(this).text());
        }); // End xData response
    } // End completefunc
}); // End SPServices

} // End Function

getMyTasks();
Aug 17, 2013 at 2:13 AM
Does anyone have any guidance on constructing the proper CAML query for a "My Tasks" list?
Aug 17, 2013 at 2:57 AM
Hi Carl,

I rely heavily on CAMLDesigner. It's a great visual tool for building CAML queries.

Cheers,

Charles
Aug 17, 2013 at 7:08 PM
There is nothing special about a Tasks list. It's just a list at its core, so your CAML query will look like any other.

What problem are you encountering?

_____
Paul

Sent from mobile device.
Aug 19, 2013 at 10:32 PM
Thank you for the help, Charles and Chris!

Charles, I'll check out CAMLDesigner -- much appreciated.

Paul, I'm trying to be slightly more ambitious and emulate the "My Tasks" query that finds a user's tasks across all lists in SharePoint as illustrated in this article. Any help/thoughts are helpful as I'm a bit of a novice.

http://blog.mastykarz.nl/inconvenient-user-tasks-web-part-display-all-tasks/

Best,
Carl
Aug 20, 2013 at 2:09 AM
With a Tasks list an Assignee field (usually) exists which is used to set to the user for which the task is assigned. But: it could be any field if type 'People and Group'. So when you say you want to get a user's tasks, you need to be aware of what column is being use to capture the assignee.

Ok. Had to get that out of the way since you said you were a novice. :)

So to retrieve the rows out of a List for the 'current logged in user' you would use the <UserId/> CAML token when querying the List. Look at this for an example of how to use this token in CAML:


There are several examples here in the forums and documentation on how to use the Lists.GetListItems operation. That together with the reference above should get you going.


_____
Paul

Sent from mobile device.