CAML query to get itemcount from sharepoint list based on Month/Year
Hi,
I have a SharePoint list with date field. Now I wan't to get item count for each month in Fiscal Year using SP Services. Hence, need a CAML query to get item count . Any suggestions will be appreciated.
Thanks in Advance.
When you have your month, you'll need to calculate the first day and last day of the month and convert them to the ISO using to ISOString.
startDate.toISOString();
endDate.toISOString();
function searchList(startDate, endDate) {
var nURL = "/_vti_bin/lists.asmx";
var soapEnv = "<?xml version=\"1.0\" encoding=\"utf-8\"?> \
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
<soap:Body> \
<GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">
<listName>{YourList}</listName> \
<viewFields></viewFields> \
<query><Query><Where><And><Geq><FieldRef Name='DateField'
/><Value Type='DateTime'>" + startDate +"</Value></Geq><Leq><FieldRef Name='DateField'><Value Type='Datetime'>"+endDate+"</Leq></And></Where></Query></query> \
<queryOptions><QueryOptions><ViewAttributes Scope='Recursive'/></QueryOptions></queryOptions>
</GetListItems> \
</soap:Body> \
</soap:Envelope>";
$.ajax({
url: nURL,
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResults,
contentType: "text/xml; charset=utf-8"
function processResults(xData, status)
var i;
result = $(xData.responseText).find("z\\:row, row");
if (result == undefined) {
result = $(xData.responseXML).find("z\\:row, row");
$(result).each(function(i, data) {
//Magic
i++;
return i;
Brandon James SharePoint Developer/Administrator
Similar Messages
-
Hi,
I am using the Javascript Client object model.
I have a custom list and a custom document library.
Custom list contains 2 columns - dlName , dlValue
The document library contains 2 folders - "folder1" , "folder2" and contains some images.
The image name starts with the "dlValue" available in the custom list
I am using a visual webpart and using javascript client object model.
I am trying to achieve the below functionality:
1) Load a dropdown with the custom list.
2) set the image based on the value in dropdown.
I have achieved the first option, I have set the dropdown, but not sure how to query the folder and set the image.
Below is the code i have used so far:
//In Visual webpart
<select id="ddlTest" >
</select>
<br/>
<div id="PreviewLayer">
<img id="imgPlaceHolder" runat="server" alt="Image" title="imgPlaceHolder" src=" " />
</div>
// In Javascript file
function RenderHtmlOnSuccess() {
var ddlTest = this.document.getElementById("ddlTest");
ddlTest.options.length = 0;
var enumerator = this.customListItems.getEnumerator();
while (enumerator.moveNext()) {
var currentItem = enumerator.get_current();
var dropdownValue = currentItem.get_item("dlValue");
ddlTest.options[ddlTest.options.length] = new Option(currentItem.get_item("dlName"), dropdownValue);
setImage(dropdownValue); // Not sure how to query the folder and set the image based on value.
// Also if dropdown value is changed, corresponding image should be shown
How to query the folder and based on dropdown value, show the image? Also, how to handle the dropdown value change?
ThanksHi,
Here are two links for your reference:
Example of how to Get Files from a Folder using Ecmascript \ Javascript client object model in SharePoint 2010
http://sharepointmantra.wordpress.com/2013/10/19/example-of-how-to-get-files-from-a-folder-using-ecmascript-javascript-client-object-model-in-sharepoint-2010/
SP2010 JSOM Client Object Model: How to get all documents in libraries including all folders recursively
http://sharepoint.stackexchange.com/questions/70185/sp2010-jsom-client-object-model-how-to-get-all-documents-in-libraries-including
In SharePoint 2013, we can also use REST API to achieve it.
http://msdn.microsoft.com/en-us/magazine/dn198245.aspx
Thanks,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Dennis Guo
TechNet Community Support -
Get Items from limited list by providing username and password - C#
I'm using the code at the following link in order to get items from SharePoint list,
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.list.getitems.aspx
I have a SharePoint list that limited to certain users.
How can I provide by this code (or else) a username and password and log in as a different user who has access to this SharePoint list and get its items?
Thanks!Sorry, previous post didn't see you were using client object model.
Service.Credentials = (create new credentials passing username and password)
ICredentials credentials = new NetworkCredential("Joe",SecurelyStoredPassword,"mydomain");
math.Credentials = credentials
Thanks!
Actually, my full question already posted here:
http: //sharepoint.stackexchange.com/questions/84917/c-why-impersonation-is-expired-while-clientcontext-executequery-is-performe
but I was unable to post it here as a new user (images, links, lenght ...) even the link above I was need to insert spaces after "http:" to be able to post it.
Anyway, I don't know "client object model." am I using it?
You mentioned "Service.Credentials", What do you mean "Service"? -
How to get data from subsites list of SharePoint 2010 in ssrs
Hi,
Can someone help me on this issue.
I want to create a report using ssrs, I have some of the data in SQL and some of the data in sharepoint list.
First I need to go to SQL and get the data from the table which contains URL for the subsite in sharepoint.
after that I need to go to all the subsites and go to perticulat list in the subsites and get data from that list.
for example, their is a top level site "abc"
it contains sub site "123", "456","567", etc.. All this sub sites contain a list by name "Sample List", Now I need to go to that sub site list(Sample List) and get list-item column say "created By" which
is created on particular date.
in my report, I need to print the sub site "url/Title" which comes from SQL database and list-item column "Created By" of that sub site list "Sample List".
I tried using subreport inside a report by using "Microsoft SharePoint List" as a datasource, but when it comes to real time we don't know how many subsites will be created, so we can't create a datasource for each subsite site.
I guess we need to be using XML as a datasource, but how can we go to particular subsite in query while using XML, since all subsites have list with the same name ?
I appreciate your help.
Thank you,
KishoreHi Kishore,
SQL Server Reporting Services(SSRS) supports expression-based connection strings. This will help us to achieve the goal you mentioned in this case:
Create a new report
Create a Data Source in the report with the connection string like this:
http://server/_vti_bin/lists.asmx (We use static connection string instead of expression-based connection string now, as it is not supported to get fields based on expression-based connection string in design time. We will change it to be expression-based
connection string later)
Create the data set(as you have done using XML query language). Please use list name instead of GUID in the listName parameter.
Design the report(e.g. Add controls to the report)
Now, let's change the connection string to be expression-based. First, please add a parameter to the report, move this parameter to top. This parameter is used to store the sub site name.
Open the Data Source editor, set the connection string to be: ="http://server/" & Parameters!parameterCreatedInStep5.value & "_vti_bin/lists.asmx"
In the main report, pass the sub site name to the report we created above via the parameter created in step5
That is all.
Anyway, this is actually a SQL Server Reporting Service(SSRS) question. You can get better support on this question from:
http://social.technet.microsoft.com/Forums/en/sqlreportingservices/threads
For more information about Expression-Based connection string, please see:
http://msdn.microsoft.com/en-us/library/ms156450.aspx#Expressions
If there is anything unclear, please feel free to ask.
Thanks,
Jinchun Chen
Jin Chen - MSFT -
CAML Query to get Items based on Year and Month From Date Column
Hi All,
* As we knew that there are default columns in calendar like Stattdate,Title,Location..etc.
* I required the CAML Query to get the list items of calender of particular Month and Year,So that I can get number of items or evetns are in Calendar
Can any one help me how can I do this using caml query
SamarHi Stuart,
Thanks for your response,I had chosen 2nd option of our above mention suggestion.But when I try to fetech the data from a calendar it is showing below error .I
had checked the below code with oter lists by changing Type to text and it worked fine.Can you please help me how can I fetech for the calulated columns
Error
"One or more field
types are not installed properly. Go to the list settings page to delete these
fields. "
Code:
string year="2014";
string month="February";
SPSite mysite = SPContext.Current.Site;
SPWeb myweb = mysite.OpenWeb();
try
SPList mylist = myweb.Lists["Calendar"];
SPQuery myquery = new SPQuery();
myquery.Query = @"<Where>
<And>
<Eq>
<FieldRef Name='Year'/>
<Value Type='Calculated'>"
+ year + @"</Value>
</Eq>
<Eq>
<FieldRef Name='Month'
/>
<Value Type='Calculated'>"
+ month + @"</Value>
</Eq>
</And>
</Where>";
SPListItemCollection totaltiems = mylist.GetItems(myquery);
Label1.Text= "Total Number of Items is "+" "+totaltiems.Count.ToString();
catch (Exception ee)
Label1.Text = ee.Message;
finally
myweb.Dispose();
Calculated Columns
Samar -
Fastest way to get data from Multiple lists across multiple site collections
HI
I need to get data from multiple lists which spread across 20 site collections and need to show it as list view.
I have searched on internet about this and got some info like options would be to use search core APIs or BCS . I can't use search because I want real time data. Not sure of any other ways.
if anybody can provide ideas it would be help.Might LINQ be an option for you? Using
LINQPad and the
SharePoint Connector, you should be able to write a query that'll retrieve this data, from which you can tabulate it. I'm not sure how you'd be able to automate this any further so that it's then imported in as list.
For something more specific, I used a third party tool called the
Lightning Tools Lightning Conductor, which is essence a powerful content roll-up tool. In one of my solutions, I created a calculated column that gave an order / ranking on each item, so that when lists were combined, they'd still have some form of
order. The web part is also fairly customisable and has always proven a useful tool.
Hope that helps.
Steven Andrews
SharePoint Business Analyst: LiveNation Entertainment
Blog: baron72.wordpress.com
Twitter: Follow @backpackerd00d
My Wiki Articles:
CodePlex Corner Series
Please remember to mark your question as "answered" if this solves (or helps) your problem. -
Caml query to retrive keyword from rich text field
hi friends
i am using below caml query to retrieve data from title field and Rich text field(Definition)
<View>
<Query>
<Where>
<And>
<Or>
<Eq>
<FieldRef Name=\'Title\'/>
<Value Type=\'Text\'>'+letter+'</Value>
</Eq>
<Contains>
<FieldRef Name=\'Definition\' />
<Value Type=\'Note\'>'+letter+'</Value>
</Contains>
</Or>
<Neq>
<FieldRef Name=\'status\' />
<Value Type=\'Text\'>Not approved</Value>
</Neq>
</And>
</Where>
<OrderBy><FieldRef Name=\'Title\' /></OrderBy>
</Query>
</View>
this query is working fine. But it is retrieving some extra fields also which doesn't have the queried string. and even it is retrieving keyword from image urls which are present in rich text field.
Please help me to retrieve key word from plain text of rich text field.Hi,
According to your post, my understanding is that you want to use caml query to retrive keyword from rich text field
By design, when specifying a ViewFields clause, values for these fields are returned, together with a few system columns like ID, Created and Modified.
If you query rich text field, it will return the field with HTML tags.
To retrieve key word from plain text of rich text field, you need to use regular expression to remove the HTML tags.
You can use the code below:
using (SPSite site = new SPSite("http://sitename"))
using (SPWeb spWeb = site.OpenWeb())
SPList spList = spWeb.Lists.TryGetList("ListName");
SPQuery qry = new SPQuery();
if (spList != null)
qry.Query =
@" <Where>
<Contains>
<FieldRef Name='Rich_x0020_Text' />
<Value Type='Note'>caml</Value>
</Contains>
</Where>";
qry.ViewFields = @"<FieldRef Name='Title' /><FieldRef Name='Rich_x0020_Text' />";
SPListItemCollection listItems = spList.GetItems(qry);
foreach (SPListItem item in listItems)
string src = item["Rich_x0020_Text"].ToString();
Regex htmlReg = new Regex(@"<[^>]+>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
src = htmlReg.Replace(src, string.Empty);
Console.WriteLine(src);
Console.ReadKey();
The result is as below:
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
Get information from multiple lists
Hi,
Environment: - SharePoint 2013
Question :- My client needs a get information from multiple list from the same site to be displayed on the page,
they would need a dropdown list with the user names , and once a user is selected all the tasks and calendar entries of the user must be filtered and displayed.
Please suggest how this can be achieved.
Satyam.Hi,
According to your post, my understanding is that you wanted to get information from multiple lists once a user was selected.
There is no out of the box way to accomplish this with SharePoint.
As a workaround, I recommend to create a list to store the user names. Then you can create relationships between lists using the browser UI. Once you select the user name in the parent list, the associated items will be displayed in the child lists.
Here are two great articles for you to take a look at:
http://office.microsoft.com/en-in/sharepoint-server-help/create-list-relationships-by-using-unique-and-lookup-columns-HA101729901.aspx#_Toc270607416
http://msdn.microsoft.com/en-us/library/ff394632.aspx
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
How to use SSIS 2014 to read from Sharepoint List ?
Hi there,
I have designed a simple entry form for users using List in Sharepoint 2013.
I need to use the information to merge into my datawarehouse.
Question :
1. How can I setup SSIS (SQL 2014) to get the source from List in Sharepoint?
I have tried to download the script as suggested in codeplex but it seems not working with SQL 2014 as there is no SSIS toolbar displayed.
Any help is much appreciated
Thank you and Best RegardsHi SylviaO,
The current
SharePoint List Adapter that extracting and loading SharePoint Data in SQL Server Integration Services supports x86/x64 systems using SQL 2005 / SQL 2008 / SQL 2008 R2/ SQL 2012. It doesn’t support SQL 2014. Maybe we need wating the update.
Besides, the
OData Source component can also be used to read from SharePoint lists. So we can download and install the 64 bit ODataSourceForSQLServer2014-amd64.msi or 32 bit ODataSourceForSQLServer2014-x86.msi from the
Microsoft® SQL Server® 2014 Feature Pack.
The following blog about using the SSIS OData Source Connector to read data from SharePoint lists is for your reference:
http://whitepages.unlimitedviz.com/2014/03/using-the-odata-source-connector-with-sharepoint-online-authentication/
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Pass the username and password in URL to auto log in the application from SharePoint List
how to Pass the username and password in URL to auto log in the application from SharePoint List
I have a link in my SharePoint list when user try to open the link its asking username and password .i want to put username and password in URL to auto log in into that external URL from sharepoint
please help me it is possibleCheck out
http://serverfault.com/questions/371907/can-you-pass-user-pass-for-http-basic-authentication-in-url-parameters
Kind regards,
Margriet Bruggeman
Lois & Clark IT Services
web site: http://www.loisandclark.eu
blog: http://www.sharepointdragons.com -
CAML query to get task assigned to current logged in user
I want to know the CAML query to get tasks assigned to the currently logged in user
NourHi,
This is the query that worked for me
<Where>
<And>
<Or>
<Membership Type=’CurrentUserGroups’>
<FieldRef Name=’AssignedTo’ />
</Membership>
<Eq>
<FieldRef Name=’AssignedTo’ LookupId=’TRUE’ />
<Value Type=’Lookup’>123</Value>
</Eq>
</Or>
<Neq>
<FieldRef Name=’Status’ />
<Value Type=’Text’>Completed</Value>
</Neq>
</And>
</Where>
Regards,
Nishant Rana
http://nishantrana.wordpress.com https://twitter.com/#!/nishantranacrm -
Getting Dates from Calendar List
If I input year as 2005 and month as Feb, I need to get list of all dates available in that year and month.
How to get it from Calendar List?If I input year as 2005 and month as Feb, I need to
get list of all dates available in that year and
month.Calculating the days in the month for the particular year is not difficult. Once that is done, the logic is simple!
Take a look at http://www.servletsuite.com/jsp.htm. It has some tags I suppose!
How to get it from Calendar List?Would you be clear on what you really want? -
Sql query to get numbers from 0 to 99
How can we write an sql query to get values from 0 to 99 ... this shouldn't be coming from any table
Bawer wrote:
Result: (quickly replied by oracle)
SQL-Error: ORA-30009 (Not enough memory for connect by - 1GB reserved for oracle on VirtualBox)Oracle version? Takes about 8 seconds on my:
SQL> select * from v$version
2 /
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
Elapsed: 00:00:00.14
SQL> select count(*) from (
2 SELECT LEVEL - 1
3 FROM DUAL
4 CONNECT BY LEVEL <= 10000000
5 )
6 /
COUNT(*)
10000000
Elapsed: 00:00:07.76
SQL> SY. -
OSLC Query to get requirements from a RequirementCollection on DOORS NG
Hi,
I'm using DOORS NG (V5.0.2) and I'm trying to get requirements referenced by a RequirementCollection using OSLC.
I tried the query given on:
https://jazz.net/library/article/1197
which is:
&oslc.prefix=rdf=<http://www.w3.org/1999/02/22-rdf-syntax-ns%23>,dcterms=<http://purl.org/dc/terms/>&oslc.select=*&oslc.where=rdf:type=<http://open-services.net/ns/rm%23Requirement>
But this query only returns the RequirementCollection itself.
So, is the query correct?Hello Jim,
In fact, as you say, that query returns all requirements on a project. I was wrong with the query that I posted and the correct one is the query that you posted, i.e.:
&oslc.prefix=oslc_rm=<http://open-services.net/ns/rm%23>,dcterms=<http://purl.org/dc/terms/>&oslc.select=oslc_rm:uses&oslc.where=dcterms:identifier=1
However, this query only returns the RequirementCollection whose identifier is 1 and it does not return its requirements.
The solution that I found and it was supported by Jazz forum (https://jazz.net/forum/questions/200343/oslc-query-for-getting-requirements-from-a-requirement-collection) is to get the RequirementCollection and using the "uses" attributes (links to the associated requirements), which contain the requirement URL, we access to requirement info. by using REST commands.
I do not have better answer than this one. If someone has a better idea, I would appreciate.
Cordially,
Carlos -
What the h*** happened to Live Updating of smart playlists in iT 11? I have several smart lists that pull from larger lists based on how recently a song has played. Not happening now. The whole library only updates "last played" for about 1 in 20 songs. This is really screwing up my lists that I use as backgrounds for a lot of activities in my classroom at school.
FYI, I've found that Live Updating can SORT OF work. It seems if you only have two rules, live upating works (IE, I have one that is a Rating must be 3-5*'s and last played cannot be within the last 8 weeks). Once the song is played it disapears off the playlist. BUT, as soon as I try to add a third rule, it doesn't work anymore! This is unfortunate because two rules really limits the ability of the playlist...
Cheers,
Maybe you are looking for
-
rying to get Photoshop CS4 functional with Mavericks and an Epson 3880 printer. CS4 fails to send a file to the print queue. Have reinstalled the Epson 3880 driver for Mavericks. All looks good but no file is sent. Does anyone know how to fix this?
-
I'm running Weblogic 7 sp2 server on a RedHat Linux 7.3 as the backend server and a Redhat 7.3 server with Apache 1.327 as the frontend. At first I had only one site to configure with the Bea Apache plugin. But there will be at least 3 sites more. I
-
How does one change preferences around so that pdfs will open in Preview and not Adobe Reader? Thanks!
-
I need to buy 1year extended warranty for my iPhone 4S can't find it in Store.
As read in the title. I'm am currently abroad with my 4S, and warranty expires today. I purchased 1 Applecare in Austria today, but it's impossible to register with my phone. They advised me to buy another one in the US store, as there are regional d
-
How hide the tab button in welcome file
i am a portal green hand,have a basic question,how can i hide a tab button in portal welcome file,and it will be visible after i login the portal