Discover the size of your SharePoint documents using K2 SmartObject

by | Apr 5, 2016 | BlogPosts, K2, Microsoft, Sharepoint, Tech Tips | 0 comments

Scenario

As a K2 developer, during a K2 Smartforms and workflow project, you may need to specify a ‘send email event’ with an attachment. This could come from either Smartforms or the workflow. However, it may be the case that you don’t want to include the attachment if its size is greater than 10MB. So, how do you find out the size of the SharePoint document, using K2 SmartObject, when the size is not known beforehand?

Here’s how:

K2 provides the Sharepoint Functions broker, in which the SharePoint MetaData Service is included:

2016-02 Blog - Sharepoint doc size from K2 Smartobjects - Image 1

Let’s make this functionality available via a Smartobject. Right click on the Sharepoint MetaData object under Sharepoint MetaData Service and select ‘Create SmartObject’.

2016-02 Blog - Sharepoint doc size from K2 Smartobjects - Image 2

Give your SmartObject an appropriate name and click ‘Publish SmartObject’:

2016-02 Blog - Sharepoint doc size from K2 Smartobjects - Image 3

After the SmartObject is created and published, we are ready to invoke it. Locate your SmartObject, under the SmartObject Explorer:

2016-02 Blog - Sharepoint doc size from K2 Smartobjects - Image 4

Right click and select ‘Execute SmartObject’. The execution window will open, as seen below.

2016-02 Blog - Sharepoint doc size from K2 Smartobjects - Image 5

Change the Method to Execute to ‘Load Document Column Value’ and fill in the Sharepoint Site URL, List Name, Folder (if required), File Name parameters and set the value ‘File_x0020_Size’ for the Column Name. ‘File_x0020_Size’ is the internal site column name associated with a Document Library. Press Execute!

2016-02 Blog - Sharepoint doc size from K2 Smartobjects - Image 6

The file size is returned in bytes.

When using this SmartObject from SmartForms or a Workflow, it is always good practise to have the Sharepoint Site URL, Document Library Name and Column Name in an environment field.

In the meantime, I really hope this was helpful. If you have any further issues, please contact us.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *