SmartObject count method


Badge +5

My smartform allows the user to upload some documents to SharePoint and then kicks off a workflow. It's also possible that documents are added to the folder from outside of the form. 

 

Later in the workflow, I need to know how many documents were uploaded. Is there a way to create a count method on a sharepoint smartobject? I'd like to count all of the documents in the particular folder.

 

Thanks in advance.


4 replies

Badge +2

Hi, since user can add documents from outside of the WF, you might have to register a service broker then create a smartobject to count the documents in the SP folders. Snippet of code to count the items in the particular folder:

 

SPSite mySite = SPContext.Current.Site;
using (SPWeb Web = mySite.OpenWeb("your site name here"))

SPFolder thisfolder = Web.GetFolder("the full folder location"); 
thisfolder.ItemCount;
}

 

pass in the URL of the SP site and the folder location. Note that the above codes requires the use of sharepoint dlls

 

HTH

YeeKhin

Badge +8

You can create a custom list that counts the items in your Document library.

 

http://pawansatope.blogspot.com/2012/01/how-to-create-count-related-lookup.html

 

The cool part about this type of count, is if your looking for different types of document categories you can do a count on them as well.  If you created a smartobject out of this count list, you could possibly load a new smartform with that data.

 

 

Badge +5

Thank you for the replies. I will give these methods a try.

 

I ended up finding a workaround myself. At the point in the workflow I needed the document count, I used a Data Event. As the source I did an inline function to count the name fields returned by the smart object list method.

Userlevel 4
Badge +13

Hi Dpknudsen



You can also created your own small counter inside of your smartforms Item view, where you can drag in a textbox with a start value of 0 (zero) onto the view and create a advanced rule on the submit button of your view that when the submit button is clicked the rule should check if the document upload control is empty or not. If the control is not empty then add one (+1) to the value in the textbox and if the document upload control is empty then do nothing.


 


You can then hide this textbox and transfer the value to the view of your choise if needed. This will be like a live updated number as well.


 


Kind Regards


Raymond

Reply