Count of items ina list using CAML Query
Hi,
Thanks in Advance
I'm using an app called blumshapiro to customize the tile in sharepoint 2013, I also have a requirement of getting the item count from the list which can be done by writing a CAML Query. Can anyone please assist me with the syntax to fetch the item count
in caml Query.
Regards,
Niranjan
Hi
There is nothing like item count in Camel query.You can get Required result using SPListItemCollection.Count
Do a normal where clause having condition.
SPQuery query = new SPQuery();
string camlquery = @"<Query>
<Where>
<Eq>
<FieldRef Name='Vendor_x0020_Product_x0020_Name'/>
<Value Type='Text'>" + xpathresultBTADSLMAX + @"</Value>
</Eq>
</Where>
</Query>";
query.Query = camlquery;
SPListItemCollection listItemCollection = list.GetItems(query);int count=0;if(listItemCollection !=null) { count=ListItemCollection.Count}MSDN reference
http://msdn.microsoft.com/en-us/library/ms467521.aspx
Regards, Rajendra Singh If a post answers your question, please click Mark As Answer on that ost and Vote as Helpful http://sharepointundefind.wordpress.com/
Similar Messages
-
Filter SharePoint list items using CAML query as same as Like operator in SQL Server.
Hi ,
I have filtered SharePoint list items based on Name using CAML query <Contains> . Now I have a new requirement is to filter list items using Like operator in SQL. But Like operator is not in CAML.
How do I filter list items using CAML as same as Like operator in SQL.
Please let me know.
Thanks in Advance.Did you try using <Contains>?
http://social.technet.microsoft.com/Forums/sharepoint/en-US/15766fd5-50d5-4884-82a1-29a1d5e38610/caml-query-like-operator?forum=sharepointdevelopmentlegacy
--Cheers -
Join two list with condition using caml query in SharePoint 2013 with client object model
Hi,
Want to join two list to get all fields from both list.
Am new to sharepoint and sharepoint 2013. Am working in sharepoint 2013 online apps. Am using context.executeQueryasync to load list and get items from list. Am able to get items from single list with caml query, but not able to get both list field values
with joins. I did lot of surfing..but not..
Below is my code..
ListName1 : "AssignedTasks"
ListName2 : "Tasks"
var assignedQueryTest = "<View><Joins><Join Type='INNER' ListAlias='Tasks'><Eq><FieldRef Name='TaskId' RefType='Id'/><FieldRef List='Tasks' Name='ID' /></Eq></Join></Joins>"
+ "<ViewFields><FieldRef Name='TitleValue' /><FieldRef Name='ActionItemsValue' /></ViewFields>"
+ "<ProjectedFields>"
+ "<Field Name='TitleValue' Type='Lookup' List='Tasks' ShowField='Title' /><Field Name='ActionItemsValue' Type='Lookup' List='Tasks' ShowField='ActionItems' />"
+ "</ProjectedFields>"
+ "</View>";
var web = context.get_web();
var list = web.get_lists().getByTitle("AssingedTasks");
var myQuery = new SP.CamlQuery();
myQuery.set_viewXml(assignedQueryTest);
var myItems = list.getItems(myQuery, "Include(TitleValue,ActionItemsValue)");
context.load(myItems);
context.executeQueryAsync(function () { if(myItems.get_count()>0){....}
}, errorCallback);
Here am able to get "AssignedTasks" list field values but not able to get "Tasks" list field values.
Can you please help me to resolve the issue. Or new idea for join. I have add the condition also in the query.
If anybody have good sample, please provide.
Thanks,
Pariventhan
Pariventhan.SHi Pariventhan,
I don't know about join but I have a workaround of this problem.
Declare one variable (itemcollection) globally. Load all the items "AssignedTasks" using context.load.
In the success method call another CAML query using <IN> tag of the ID of the items from the second list (Assuming you have look-up column of the ID of the first list to the second list).
If this is not clear to you then please let me know. If possible then I can provide code sample.
Thanks,
Aniruddha -
Retrieve all items in a list by caml query then write it to a word file page by page
Dears,
Greetings
I have some code which will retrieve all items of a list with caml query.
Now i want to generate a word file with all these retrieved data. I am using foreach here to get all the items in a SPListItemCollection. Now my question is how i can write all the retrieved items inside the word file?
see the below code which is writing only the last row item of the SPListItemCollection inside word file. I want to write all the retrieved rows inside this word file.
SPQuery qry = new SPQuery();
qry.Query = "<Where><Eq><FieldRef Name='Department' /><Value Type='Text'>HR DEPARTMENT</Value></Eq></Where>";
SPListItemCollection listItems = KPILIst.GetItems(qry);
foreach (SPListItem item in listItems)
lblBadgeNo.Text = item["Badge No"].ToString();
lblName.Text = item["Name"].ToString();
lblPosition.Text = item["Position"].ToString();
lblDept.Text = item["Department"].ToString();
lblHireDate.Text = item["Hire Date"].ToString();
lblGrade.Text = item["Grade"].ToString();
lblCurStatus.Text = item["Status"].ToString();
string FinalOut = "";
FinalOut = "<table cellpadding=0 cellspacing=0><tr><td style='height:30px;'></td></tr><tr><td style='height:22px;'></td></tr>";
FinalOut = FinalOut + "<tr><td style='text-align:justify;font-size:22px;'>" + lblBadgeNo.Text + "</td></tr>";
FinalOut = FinalOut + "<tr><td style='text-align:justify;font-size:22px;'>" + lblName.Text + "</td></tr>";
FinalOut = FinalOut + "<tr><td style='text-align:justify;font-size:22px;'>" + lblDept.Text + "</td></tr>";
FinalOut = FinalOut + "<tr><td style='text-align:justify;font-size:22px;'>" + lblHireDate.Text + "</td></tr>";
FinalOut = FinalOut + "</table>";
System.Text.StringBuilder strBody = new System.Text.StringBuilder("");
strBody.Append("<html " + "xmlns:o='urn:schemas-microsoft-com:office:office' " + "xmlns:w='urn:schemas-microsoft-com:office:word'" + "xmlns='http://www.w3.org/TR/REC-html40'>" + "<head><title>EPCCO : HR Comapny Letter</title>");
strBody.Append("<!--[if gte mso 9]>" + "<xml>" + "<w:WordDocument>" + "<w:View>Print</w:View>" + "<w:Zoom>90</w:Zoom>" + "<w:DoNotOptimizeForBrowser/>" + "</w:WordDocument>" + "</xml>" + "<![endif]-->");
strBody.Append("<style>" + "<!-- /* Style Definitions */" + "@page Section1" + " {size:8.5in 11.0in; " + " margin:1.0in 1.25in 1.0in 1.25in ; " + " mso-header-margin:.5in; " + " mso-footer-margin:.5in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;}" + "-->" + "</style></head>");
strBody.Append("<body dir=rtl lang=EN-US style='tab-interval:.15in'>" + "<div class=Section1>" + FinalOut.ToString() + "</div></body></html>");
Response.AppendHeader("Content-Type", "application/msword");
Response.AppendHeader("Content-disposition", "attachment; filename=Eval_" + lblBadgeNo.Text + ".doc");
Response.Write(strBody);
Regards
Shaji
I am new to SharePointHello,
you can try with OpenXML SDK to create word file. I found one link for your reference:
http://sharepointplace.blogspot.in/2009/12/programmatically-creating-word.html
Another way is , use Microsoft Word Object Library.
http://social.msdn.microsoft.com/Forums/vstudio/en-US/5b82c0b5-ecaf-40f2-a68a-c7c17c85414f/create-word-documents-by-c?forum=csharpgeneral
Hope it could help
Hemendra:Yesterday is just a memory,Tomorrow we may never see
Please remember to mark the replies as answers if they help and unmark them if they provide no help -
How to retrieve Task Lists from All Subsites to the Parent Site and display in Grid view using CAML Query + object model
do u just want task list or items under task list for all subsites
for items use spsitedataquery ref
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.aspx use recursive to get it from alll subsite under site collection
for tasklist only u can a simply use a for loop to find in all subsite
Manish Sati -
Sum and group by using CAML query
Is there any way to get the SUM of values with group by ID using CAML query?
I have a custom list, in that I have ID and Value columns as below
ID Value1 Value2
1 10 4
2 5 3
1 15 2
3 20 1
I want to get result:
ID Value1 Value2
1 25 6
2 5 3
3 20 1
I used CAML query:
<View>
<Query>
<Where>
<IsNotNull>
<FieldRef Name="ID" />
</IsNotNull>
</Where>
<GroupBy Collapse="FALSE">
<FieldRef Name="ID" />
</GroupBy>
</Query>
<ViewFields>
</ViewFields>
<Aggregations Value="On">
<FieldRef Name="Value1" Type="SUM" />
<FieldRef Name="Value2" Type="SUM" />
</Aggregations>
</View>
But
this query returns all the records
that satisfy the condition <Where>.
I
do not correctly?You need to work with current view based aggregation. Please check below threads for your reference.
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/dda5735a-fecf-403f-9495-1b63617d2fbf/question-on-a-caml-query?forum=sharepointdevelopmentlegacy
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/24e88d6a-ee15-4d81-a5fe-504c7bd14e46/how-to-sum-a-column-value-using-caml-query?forum=sharepointdevelopment
Hope this helps.
My Blog- http://www.sharepoint-journey.com|
If a post answers your question, please click Mark As Answer on that post and Vote as Helpful
I've seen these
issues and articles and do them, but
does not work. I use object mozhel
Sharepoint (javascript). -
Copy one list items new list using client side object model
Hi,
I have a requirement like i need to copy one list information to new list with createdby and modified by fields.I need to use client side object model code.Can u please send me the code sample.
Regards,
PraveenHi,
According to your post, my understanding is that you want to copy one list items new list using client side object model.
You can use console application.
Here is a similar thread for your reference:
https://social.technet.microsoft.com/Forums/sharepoint/en-US/28a43891-7505-4d34-b513-fdd66773c2a3/copy-list-item-to-another-list-using-client-object-model-in-console-application?forum=sharepointdevelopmentprevious
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
Join two list of integer type field using CAML query
Hi
As i am struggling in Join two sharepoint list (Roles and Emplyees). As there is no lookup columns and lists are already existing and have almost 3000 + recodrs. As a part of enhancement work need to join these list. List structure is some thing as follows:
Roles :
ID Title
1 Project Manager
2 Business Analyst
3 Developer
Employees :
Name Role
1 James 1
2 Petar 3
3 John 2
Output should be like as follows:
Name Role
1 James Project Manager
2 Petar Developer
3 John Developer
So please suggest, if the joining can be done other than lookup columns through the CAML query.
Akhilesh RaoFollow below CAML query to add joins between two lists.
SPList list = SPContext.Current.Site.RootWeb.Lists["Employees"];
SPQuery query = new SPQuery();
query.Joins = @" <Join Type="INNER" ListAlias="Roles">
<Eq>
<FieldRef Name="Employees" RefType="Role" />
<FieldRef List="Roles" Name="ID" />
</Eq>
</Join>";
query.ProjectedFields = @" <Field Name="RoleName" Type="Lookup" List="Roles" ShowField="Title">";
query.ViewFields = @ "<FieldRef Name="Title">
<FieldRef Name="RoleName"> ";
SPListItemCollection result = tablea.GetItems(query);
Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer :) -
Using CAML Query in SharePoint Hosted app
Hi,
I am trying to execute a CAML Query in a SharePoint Hosted App, below is the JS code.
executor.executeAsync({
url: appwebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('Documents')/Items?/getitems?@target='" + hostweburl + "'",
method: "POST",
body: { 'query' : {'__metadata': { 'type': 'SP.CamlQuery' }, "ViewXml": "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='TEXT'>value</Value></Eq></Where></Query></View>"
headers: {
"accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
success: successHandler,
error: errorHandler
getting an error: Uncaught Error: "Invalid field or parameter requestInfo.body"Are you using rest api?
Please check this
http://tech.bool.se/using-caml-sharepoint-rest-api/
http://msdn.microsoft.com/en-us/library/office/dn531433(v=office.15).aspx -
How to get Items per Set by CAML Query?
Hi,
I have these data
ItemName
Item1
Item2
Item3
Item4
Item5
Item7
Item8
I want to query them per set, how can I achieve this output using CAML
Query1:
Item1
Item2
Item3
Query2:
Item4
Item5
Item6
ThanksHello,
You can't do it easily. But you may add one more column and give some unique value as per set so you can query the list. However you can use <rowlimit> to return only 3 items but you have to add extra code (i.e. cache set in some table).
Hemendra:Yesterday is just a memory,Tomorrow we may never see<br/> Please remember to mark the replies as answers if they help and unmark them if they provide no help -
Hello Experts,
i have created a report where i have one parameter field where user will pass parameter(e.g. EmpId). As per parameter record will fetched to report if no parameter is passed then it will display all records. I have done it by taking SqlServer Database as datasource.
by using Following method
Now i would like to do it by taking Sharepoint List as Datasource. For that what would be the CAML Query.
Here is my existing CAML query.
<RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ListName>Employees</ListName>
<ViewFields>
<FieldRef Name="Title" />
<FieldRef Name="FirstName" />
<FieldRef Name="LastName" />
<FieldRef Name="FullName" />
<FieldRef Name="UserName" />
<FieldRef Name="Company" />
</ViewFields>
<Query>
<Where>
<Eq>
<FieldRef Name="Title" />
<Value Type="Text">
<Parameter Name="EmployeeId"/>
</Value>
</Eq>
</Where>
</Query>
</RSSharePointList>
The above code is working if i am passing an employeeId to Parameter. If nothing is passed, it is Not retrieving any record.
Please suggest
Thank you
saroj
sarojYour problem follows the well-established pattern of using an "All" parameter filter in SSRS. There are a few approaches depending on the size of your data. The easiest one is to return all data from CAML and then filter it within SSRS, the following thread
provides some examples,
http://stackoverflow.com/questions/18203317/show-all-records-some-records-based-on-parameter-value.
Other options include passing all of the possible values within the CAML query when "All" is selected, using multiple Report Files to distinguish between both CAML queries, or to use multiple datasets with some logic to show/hide the correct one.
Dimitri Ayrapetov (MCSE: SharePoint) -
How to sum a column value using CAML Query?
Hi All,
I would like to sum the column value using CAML qeury. Actually in my list, I have two column "Projects Name" and "Number of Issues". Now need to get sum of "Number of Issues" column. How to achieve in CAML Query.
Thanks in advance!Hi Sam,
it looks like you can use your current view based agregation, otherwise it is not possible(
http://msdn.microsoft.com/en-us/library/ms467521.aspx) and you need to work on custom bit on this requirement.
use the below link and create a view element as described and see if that works for you
Aggregations Element
http://msdn.microsoft.com/en-us/library/ms468626%28v=office.12%29.aspx
Another reference
Query Element
http://msdn.microsoft.com/en-us/library/ms471093.aspx
Hope this helps!
Ram - SharePoint Architect
Blog - SharePointDeveloper.in
Please vote or mark your question answered, if my reply helps you -
Create Multiple tasks for Single Item in List using state machine workflow in sharepoint
Hi,
I want to create multiple create tasks for Single Item in List based on Assigned to column using state machine Workflow through visual studio
Here Assigned to column allows multiple users. so i have to create task for every user based on column .
I'm trying for this but i didn't got any solution
Please provide solution for this.Hi,
According to your post, my understanding is that you wanted to allow multiple users to approve.
There are some articles about creating parallel tasks in state machine workflow, you can have a look at them.
http://www.codeproject.com/Articles/477849/Create-Parallel-Task-in-State-Machine-Workflow-in
http://msdn.microsoft.com/en-us/library/office/hh128697(v=office.14).aspx
http://social.technet.microsoft.com/Forums/office/en-US/b16ee858-4360-479a-a686-4ee35b7be9db/sharepoint-2010-workflow-creating-multiple-tasks?forum=sharepointdevelopmentprevious
Thanks & Regards,
Jason
Jason Guo
TechNet Community Support -
Problem adding item to list using a function. Error - Null pointer
Hi Guys,
I'm not sure what the problem is, but for some reason I am unable to add an item to a list using a function. I can add an item when I call it in the same function that the list is created, but I cannot add the item from anoter function. Here is the code:
Main:
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class main {
* @param args
public static void main(String[] args) {
JFrame JFrame = new JFrame();
JFrame.setSize(400,400);
testpanel panel1 = new testpanel();
panel1.setBackground(Color.red);
JPanel panel2 = new testpanel();
panel2.setBackground(Color.BLUE);
JFrame.add(panel1);
JFrame.add(panel2);
JFrame.setLayout(new FlowLayout());
//THIS GIVES ERROR:
//NullPointerException
panel1.addListItem("test");
JFrame.setVisible(true);
}And here is the testpanel class:
* To change this template, choose Tools | Templates
* and open the template in the editor.
* testpanel.java
* Created on Apr 7, 2010, 6:10:24 PM
import java.awt.List;
import java.awt.ScrollPane;
import java.awt.event.ActionListener;
* @author Snowraver1
public class testpanel extends javax.swing.JPanel {
public void addListItem(String string){
list.add(string);
/** Creates new form testpanel */
public testpanel() {
initComponents();
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jButton1 = new javax.swing.JButton();
ScrollPane scrollPane = new ScrollPane();
List list = new List();
jButton1.setText("jButton1");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(49, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(46, 46, 46))
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(123, 123, 123)
.addComponent(jButton1)
.addContainerGap(139, Short.MAX_VALUE))
this.add(scrollPane);
scrollPane.add(list);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private ScrollPane scrollPane;
private List list;
// End of variables declaration//GEN-END:variables
}Thanks for the help!
-- SnowYou should check how you are initializing your variables in your testpanel class. You initialize your button correctly, but your other class variables are being overridden. As a result, your class variables still have a value of 'null'.
-
Update item in list using rest api - failed when browsing in juniper session
this issue is about browsing to an on premises sharepoint 2013 inside a LAN using Juniper session
the user can see everything and can create new list items with rest api but
cannot update existing items using the function below.
we've got this function which we use to update list items in rest
it works like a charm when browsing inside the LAN
function updateListItem(itemIdentityField, itemIdentity, listName, siteUrl, item, success, failure) {
getListItemWithId(itemIdentityField, itemIdentity, listName, siteUrl, function (data) {
$.ajax({
url: data.__metadata.uri,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"If-Match": data.__metadata.etag
success: function (data) { success(data, callBackIndex, null) },
error: function (data) {
getError(data);
}, function (data) {
failure(data);
the error i get in ULS log is:
Original error: Microsoft.SharePoint.Client.InvalidClientQueryException: The parameter __metadata does not exist in method GetItemByStringId.
at Microsoft.SharePoint.Client.MethodInformation.GetParameter(String parameterName)
at Microsoft.SharePoint.Client.ClientCallableEdmModelBuilder.CreateFunctionImportForMethodBodyParser(MethodInformation clientMethod, List`1 parameterNames, ProxyContext proxyContext)
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.ParseParametersFromBody(MethodInformation methodInfo, Boolean allowPostBodyAccess, Boolean isLeafSegment, ClientValueCollection args)
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.ParseParametersFromBodyOrQueryString(MethodInformation methodInfo, Boolean allowPostBodyAccess, Boolean isLeafSegment, ClientValueCollection args)
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.CreateMethodArgumentsUsingNamedParameters(MethodInformation methodInfo, IList`1 parameterList, Boolean isLeafSegment, Boolean allowPostBodyAccess)
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.InvokeMethod(Boolean mainRequestPath, Object value, ServerStub serverProxy, EdmParserNode node, Boolean resourceEndpoint, MethodInformation methodInfo, Boolean isExtensionMethod, Boolean isIndexerMethod)
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.GetObjectFromPathMember(Boolean mainRequestPath, String path, Object value, EdmParserNode node, Boolean resourceEndpoint, MethodInformation& methodInfo)
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.GetObjectFromPath(Boolean mainRequestPath, String path, String pathForErrorMessage)
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.Process()
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.ProcessRequest()
at Microsoft.SharePoint.Client.Rest.RestService.ProcessQuery(Stream inputStream, IList`1 pendingDisposableContainer)
Any help?
Somebody?
ThanksHi patrik
Really appreciate your replying.
Could you try and refer to the issues below:
this error occurs even with site collection administrator (i tested it with three different
users)
there isnt any difference between items in list - all have same permissions
it occurs in several lists in site (all lists have same permissions)
if browsing inside the LAN everything works just fine
updating from the UI works fine in all means
It really seems like a Rest related problem(is there anyone from the Microsoft REST team who can take look at this error?)
Thanks
Hushay
Maybe you are looking for
-
Do I have to jettison my Thunderbird account. I'm a victim of the Home Depot hackers, and my mail is filled daily by often vile trash. Thunderbird won't ban this crap, as Gmail does. What do I do?
-
Confirmation of Finish Goods Non Valuated for MTO
Hello SAPper Friends, I was doing a Make to Order production with Strategy 20. When I was doing the confirmation with at least four operations, in the first operation was fine, movement type 261 was posted for the components and also in the last oper
-
Quality is so bad exporting to H.264
I don't know why but this project I'm working on I can't seem to export it like I always do. For starters the transparency of a font I'm using is messed up and its like there is this film covering the entire video. I'm thinking now its my old graphic
-
1120: Access of undefined property sendbtn.
What would cause this I have a button named sendbtn but it causes this error like 4 times
-
New Scenario - RE-FX Paying amount to Supplier ou business Partner.
Hi Guys. I would like know if I can create a scenario in RE-FX where I have a lease of property with a particular vendor, but I'll be paying the rent. Example: Create a contract that mensamenlte I pay a certain amount to that supplier / partner. Type