I have a CAML query where I am trying to retrieve records based on the logged in users id.
The following query works on my dev & qa environments, but not in my production environment. There is data that exists that matches the user. I have also tested inside SP CAML Query Helper and again there is 0 results returned.
I have tried:
<Where>
<Eq>
<FieldRef Name='SharepointUser' LookupId='TRUE'/><Value Type='Integer'>37</Value>
</Eq>
</Where>
<Where>
<Eq>
<FieldRef Name='SharepointUser' LookupId='TRUE'/><Value Type='User'>37</Value>
</Eq>
</Where>
<Where>
<Eq>
<FieldRef Name='SharepointUser' LookupId='TRUE'/><Value Type='Lookup'>37</Value>
</Eq>
</Where>
SharepointUser is of Type="User"
Is there some setting that I am missing that I need to set for Lookups to work appropriately?
If you are looking for the current user's ID, you should use the <UserID/> CAML element, like this:
<Where>
<Eq>
<FieldRef Name="SharepointUser" LookupId="TRUE"/><UserID/>
</Eq>
</Where>
Related
I am leveraging SPservices within a SharePoint 2013 environment to create filtered views unique to the current user. Effectively, when a user visits a page, they get a custom feed of documents that they have uploaded to a specific library.
I can successfully query the library and render the results they way I want, but when I attempt to create a compound CAML query, I keep getting errors. I have tried using the various resources here to manually build this query (and do to network restrictions I cannot use the U2U CAML builder tool), but I keep getting thrown errors. I started doing simple queries and it was working, but once I try to get to my third and forth "OR" statements (including a IsNull argument), I hit a wall. I think I am improperly nesting my statements and would love some help in identifying what I am doing wrong.
<Where>
<And>
<Contains>
<FieldRef Name='Author' />
<Value Type='User'>" + userName + "</Value>
</Contains>
<And>
<Eq>
<FieldRef Name='ContentType' />
<Value Type='Computed'>Document</Value>
</Eq>
</And>
<Or>
<Or>
<Or>
<Or>
<Eq>
<FieldRef Name='sensitivity' />
<Value Type='Choice'>Low</Value>
</Eq>
<Eq>
<FieldRef Name='sensitivity' />
<Value Type='Choice'>Medium</Value>
</Eq>
</Or>
<Eq>
<FieldRef Name='sensitivity' />
<Value Type='Choice'>High</Value>
</Eq>
</Or>
</Or>
<IsNull>
<FieldRef Name='sensitivity' />
</IsNull>
</Or>
</And>
</Where>
The desired result would be an output of items that the current user uploaded / created WHERE the Content Type is equal to "Document" AND the Sensitivity (choice) field is equal to Low, Medium, High or is empty.
I feel like I am really close, but I am making a silly mistake. For context, the "userName" reference in the statement is a javascript variable that is functioning properly.
The bracketing can be quite confusing without a tool like the U2U CAML builder tool. I feel your pain.
I think your issue may be the isnull at the end. I believe you would want is NotNull
<IsNotNull>
<FieldRef Name='sensitivity' />
</IsNotNull>
As a last ditch you might be able to just query all files by user whos documents co
To start off, I would like to thank anyone in advance for the help. I am using SharePoint 2013, SharePoint designer 2013, and attempting to create a new filtered view...
I have a list of entries that has a column which contains multiple username's.
Ex: Username1 Username2 Username3
What I'm looking to do is filter the view based upon whether or not the UserIDs column contains the currently logged in user. I've found a couple of walk throughs on this issue but none seem to work (I can't seem to make it do so). I believe the reason it does not work is because our SharePoint environment adds a 'salt' to the beginning of each username it pulls.
Ex: i:0#.w|DomainName\UserName
As you can tell in the column above, I'm substringing all of the Salt/Domain information out. Would anyone happen to know if this is possible?
If so, do I need to use Jscript to pull the username before I filter?
Below are three more examples of what I've tried....
<Where>
<Contains>
<FieldRef Name='UserIDs' />
<Value Type='User'>System Account</Value>
</Contains>
</Where>
<Where>
<Contains>
<FieldRef Name='UserIDs' LookupId='True' />
<Value Type='User'>1073741823</Value>
</Contains>
</Where>
<Where>
<Contains>
<FieldRef Name='UserIDs'/>
<Value Type='User'><UserID/></Value>
</Contains>
</Where>
I've used these two before and they worked:
<Where>
<Eq>
<FieldRef Name="UserIDs" LookupId="TRUE" />
<Value Type="User">1073741823</Value>
</Eq>
</Where>
<Where>
<Eq>
<FieldRef Name="UserIDs" LookupId="TRUE" />
<Value Type="Lookup">1073741823</Value>
</Eq>
</Where>
I am having issues setting more than three filters using the queryoverride property. It works just fine if i pass fixed values to the fields like instead of [PageFieldValue:Primary Office], if i feed in 'XYZ Office' then it is able to read that value and pull content based on it...but not with the PageFieldValue...I am trying to pull content from other pages in the page libray that match the primary office value of the current page...so If I am in Doctor X's page and his primary office is XYZ then it should pull all other doctors from XYZ Office, where XYZ office could be the other doctor's primary office or other extra practice location?? Please any sharepoint GURU??
<Query>
<Where>
<And>
<Neq>
<FieldRef Name='Title' />
<Value Type='Text'>[PageFieldValue:Title]</Value>
</Neq>
<Or>
<Eq>
<FieldRef Name='Office' />
<Value Type='Text'>[PageFieldValue:Primary Office]</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='Office1Name2' />
<Value Type='Text'>[PageFieldValue:Primary Office]</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='OtherOffice2Name' />
<Value Type='Text'>[PageFieldValue:Primary Office]</Value>
</Eq>
<Eq>
<FieldRef Name='OtherOffice3Name' />
<Value Type='Text'>[PageFieldValue:Primary Office]</Value>
</Eq>
</Or>
</Or>
</Or>
</And>
</Where>
</Query>
I have the following CAML query:
<Where>
<And>
<Eq>
<FieldRef Name='PublishToSM' />
<Value Type='Boolean'>True</Value>
</Eq>
<IsNull>
<FieldRef Name='SMUpdateDate' />
</IsNull>
</And>
</Where>
I have only one content type that uses these fields. When I run this query against a list that uses this content type everything works fine. When I run it against a List that does not it throws the error: One or more field types are not installed properly. Go to the list settings page to delete these fields.
I would like to be able to search all Lists on all websites in a site collection. Can this be done without erroring out?
Use SPSiteDataQuery, add a where clause to include the content type. i.e.:
<Where>
<And>
<Eq>
<FieldRef Name='ContentType' />
<Value Type='Text'>CONTENTTYPE NAME</Value>
</Eq>
<And>
<Eq>
<FieldRef Name='PublishToSM' />
<Value Type='Boolean'>True</Value>
</Eq>
<IsNull>
<FieldRef Name='SMUpdateDate' />
</IsNull>
</And>
</And>
</Where>
<BeginsWith>
<FieldRef Name='ContentTypeId' />
<Value Type='ContentTypeId'>CONTENTTYPE ID</Value>
</BeginsWith>
Set the SPSiteDataQuery's Scope property to SiteCollection. By setting the Lists property you can also limit the search to for instance document libraries etc. The ViewFields property can be set to limit the fields retrieved (i.e. instead of the equivalent of a select * on the items's fields)
In SP2007/MOSS I need to run a CAML query against a single list like so:
<Where>
<Or>
<Eq>
<FieldRef Name='URL' />
<Value Type='URL'>/path/item1.aspx</Value>
</Eq>
<Eq>
<FieldRef Name='URL' />
<Value Type='URL'>/path/item4.aspx</Value>
</Eq>
<Eq>
<FieldRef Name='URL' />
<Value Type='URL'>/path/item7.aspx</Value>
</Eq>
</Or>
</Where>
The practical outcome of this would be that I have a SPListItemCollection of the items for which I had the URLs.
However, I am getting an error 'One or more field types are not installed properly. Go to the list settings page to delete these fields.'
All of the items in the list are of the same content type. The only relevant error in the SP logs shows the same message.
The answer did not solve this specific problem but did end up being correct (Or's have to be nested). The problem was that my field Value Type should have been FileRef.
This error is almost always because your CAML query is incorrect. Have you tried formatting it like this:
<Where>
<Or>
<Eq>
<FieldRef Name='URL' />
<Value Type='URL'>/path/item1.aspx</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='URL' />
<Value Type='URL'>/path/item4.aspx</Value>
</Eq>
<Eq>
<FieldRef Name='URL' />
<Value Type='URL'>/path/item7.aspx</Value>
</Eq>
</Or>
</Or>
</Where>
I'm pretty sure you can only have two components in an Or or And branch.