1

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?

3 Answers 3

2

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.

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

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.

1
  • How to implement this in Content Editor WebPart.
    – Strider
    Dec 2, 2011 at 7:03
0

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

2
  • 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, 2011 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, 2011 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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