Querying Sharepoint for Library item count

B

bshea

I have a desire to query Sharepoint from an Infopath form to determine the
number of items currently in a form library.

I have created a "request data" data connection called "Count New" which
points to my site, the the "New Requests" library, and gets the ID field. It
is setup to automatically retrieve data when form is opened.

From this point I had hoped to use:
function CountNewRequests()
{
// Counts the current New Requests
var inNewCount;
var obNewList;

// Get data from Data Connection
obNewList = XDocument.DataAdapters("Count New").QueryAdapater;
inNewCount = obNewList.Count();

return inNewCount;
}

When I do, the obNewList errors out with an "Object Null or Undefined"
message. I believe my next line is not correct either but I can't test that
until I get the correct return from my query.

Any thoughts on the error, or better on how to get the count of items in my
sharepoint library?

Thanks for any pointers you can give!
 
S

S.Y.M. Wong-A-Ton

Using a simple count() on a repeating field from the data connection should
do the trick from within a formula. Any particular reason why you want to use
code?

But if you insist on using code, try using XDocument.DataObject["Count New"]
instead of XDocument.DataAdapters("Count New").QueryAdapater. Then use a
selectNodes on XDocument.DataObject["Count New"].DOM to retrieve all of one
of the repeating nodes (e.g. an ID field) in the data connection, and then
use the "length" property on the object returned by selectNodes to get the
amount of items. Note: The amount might be limited by the limit set on the
amount of items shown through the Default View of the library in SharePoint.
 
B

bshea

I'm not set on using code, but the overall intent was to have this form count
the number of submissions in the library of new requests so it could alert
the person submitting a new request of "queue depth". I'm essentially
counting the New and Accepted requests, then generating a ballpark SLA for
start time based on existing queue depth, delevery time, and SLA.

I'll play around with both suggestions though and see what I can get to
work, many thanks for hte pointers and I'll post back with the final answer.

S.Y.M. Wong-A-Ton said:
Using a simple count() on a repeating field from the data connection should
do the trick from within a formula. Any particular reason why you want to use
code?

But if you insist on using code, try using XDocument.DataObject["Count New"]
instead of XDocument.DataAdapters("Count New").QueryAdapater. Then use a
selectNodes on XDocument.DataObject["Count New"].DOM to retrieve all of one
of the repeating nodes (e.g. an ID field) in the data connection, and then
use the "length" property on the object returned by selectNodes to get the
amount of items. Note: The amount might be limited by the limit set on the
amount of items shown through the Default View of the library in SharePoint.
---
S.Y.M. Wong-A-Ton


bshea said:
I have a desire to query Sharepoint from an Infopath form to determine the
number of items currently in a form library.

I have created a "request data" data connection called "Count New" which
points to my site, the the "New Requests" library, and gets the ID field. It
is setup to automatically retrieve data when form is opened.

From this point I had hoped to use:
function CountNewRequests()
{
// Counts the current New Requests
var inNewCount;
var obNewList;

// Get data from Data Connection
obNewList = XDocument.DataAdapters("Count New").QueryAdapater;
inNewCount = obNewList.Count();

return inNewCount;
}

When I do, the obNewList errors out with an "Object Null or Undefined"
message. I believe my next line is not correct either but I can't test that
until I get the correct return from my query.

Any thoughts on the error, or better on how to get the count of items in my
sharepoint library?

Thanks for any pointers you can give!
 
B

bshea

Still failing. Object null again. This time on the DataObject line. Going
to scrap this function as it clear doesn't work as I need / want it too.

Thanks anyway.

bshea said:
I'm not set on using code, but the overall intent was to have this form count
the number of submissions in the library of new requests so it could alert
the person submitting a new request of "queue depth". I'm essentially
counting the New and Accepted requests, then generating a ballpark SLA for
start time based on existing queue depth, delevery time, and SLA.

I'll play around with both suggestions though and see what I can get to
work, many thanks for hte pointers and I'll post back with the final answer.

S.Y.M. Wong-A-Ton said:
Using a simple count() on a repeating field from the data connection should
do the trick from within a formula. Any particular reason why you want to use
code?

But if you insist on using code, try using XDocument.DataObject["Count New"]
instead of XDocument.DataAdapters("Count New").QueryAdapater. Then use a
selectNodes on XDocument.DataObject["Count New"].DOM to retrieve all of one
of the repeating nodes (e.g. an ID field) in the data connection, and then
use the "length" property on the object returned by selectNodes to get the
amount of items. Note: The amount might be limited by the limit set on the
amount of items shown through the Default View of the library in SharePoint.
---
S.Y.M. Wong-A-Ton


bshea said:
I have a desire to query Sharepoint from an Infopath form to determine the
number of items currently in a form library.

I have created a "request data" data connection called "Count New" which
points to my site, the the "New Requests" library, and gets the ID field. It
is setup to automatically retrieve data when form is opened.

From this point I had hoped to use:
function CountNewRequests()
{
// Counts the current New Requests
var inNewCount;
var obNewList;

// Get data from Data Connection
obNewList = XDocument.DataAdapters("Count New").QueryAdapater;
inNewCount = obNewList.Count();

return inNewCount;
}

When I do, the obNewList errors out with an "Object Null or Undefined"
message. I believe my next line is not correct either but I can't test that
until I get the correct return from my query.

Any thoughts on the error, or better on how to get the count of items in my
sharepoint library?

Thanks for any pointers you can give!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top