Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have been searching this site for an answer but I have been unable to find anything that will work.

I have been trouble pulling the tasks of the current user from a subsite. I am using SharePoint 2007 and I want to be able to display tasks that are assigned to the logged in user and has not been completed yet. I suspect something is wrong with CAML. When the query is not included, the CEWP displays all the tasks in the task list.

var soapEnv =
    "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
        <soapenv:Body> \
            <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                <listName>Tasks</listName> \
                <viewFields> \
                    <ViewFields> \
                        <FieldRef Name='Title' /> \
                        <FieldRef Name='ID' /> \
                    </ViewFields> \
                </viewFields> \
                <query> \
                    <Query> \
                        <Where> \
                            <And> \
                                <Eq> \
                                    <FieldRef Name=’AssignedTo’></FieldRef> \
                                    <Value Type=’Integer’><UserID Type=’Integer’ /></Value> \
                                </Eq> \
                                <Neq> \
                                    <FieldRef Name=’Status’/> \
                                    <Value Type=’Text’>Completed</Value> \ 
                                </Neq> \
                            </And> \
                        </Where> \
                  </Query> \
                </query> \
            </GetListItems> \
        </soapenv:Body> \
    </soapenv:Envelope>";

Does anyone have any ideas?

share|improve this question
add comment

3 Answers

I second James' suggestion to use SPServices, but I wrote it, so I'm not to be trusted.

It looks like you might have "smart quotes" in your query:

<FieldRef Name=’AssignedTo’>

Make sure those are "straight quotes" instead.

share|improve this answer
    
The quotes are correct in the query. They showed up as the curved quotes when I copy pasted it into here. –  doubledian Jul 11 '11 at 19:48
    
I'd delete the quotes and re-add them, just to be doubly (lol, pun) sure. –  James Love Jul 11 '11 at 20:11
add comment
up vote 1 down vote accepted

Here is what ended up finally working:

var soapEnv =
    "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
        <soapenv:Body> \
            <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                <listName>Tasks</listName> \
                <query> \
                    <Query> \
                        <Where> \
                            <And> \
                                <Eq> \
                                    <FieldRef Name='AssignedTo'></FieldRef> \
                                    <Value Type='Integer'><UserID Type='Integer' /></Value> \
                                </Eq> \
                                <Neq> \
                                    <FieldRef Name='Status'></FieldRef> \
                                    <Value Type='Choice'>Completed</Value> \
                                </Neq> \
                            </And> \
                        </Where> \
                    </Query> \
                </query> \
                <viewFields> \
                    <ViewFields> \
                        <FieldRef Name='Title' /> \
                        <FieldRef Name='ID' /> \
                    </ViewFields> \
                </viewFields> \
            </GetListItems> \
        </soapenv:Body> \
    </soapenv:Envelope>";

I fooled around with the CAML and it finally worked.

share|improve this answer
    
How to implement this in Content Editor WebPart. –  Strider Dec 2 '11 at 7:03
add comment

You have 'query' nested inside a 'Query' block. Only use the Query with the upper case, and remove the one in lower case.

share|improve this answer
    
i removed the <query> and </query> and it did not work. I thought you needed to lower case <query> to signify the query portion of the envelope and the <Query> to signify the actual query –  doubledian Jul 11 '11 at 17:11
    
There's something similar with the viewFields portion, too. Direct injection of SOAP envelopes is a pretty unstable way of accessing the web services, have you tried using SPServices? This greatly reduces the complexity of simple tasks like querying lists. spservices.codeplex.com –  James Love Jul 11 '11 at 17:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.