Solved

Count Number of Items Returned By List SmartObject

  • 13 November 2014
  • 7 replies
  • 275 views

Badge +1

I have been asked if is possble to conditionaly perform an action depending on the number of results returned after executing a smart object. i.e if one result transfer values to controls ELSE display a subform with all results.

 

Obviously to do this need be able to count the number of items returned from the smart object.I cannot see any native way to do this so i've started to look for work arounds.

 

I've looked at creating an expression and using the List Affregators - List Count operator. This worked on a List view but not on an item view. I have tried using this expression against a drop-down-list data source but it hasn't worked.

 

Is anyone able to assit, or should I abandon all hope?

 

Regards,

Clayton

icon

Best answer by JohanL 14 November 2014, 14:10

View original

7 replies

Badge +5

Hi,

 

You could try using an advanced conditon to check against a trasnfered value.

 

Take a look at this link, might give you an idea  of how to create a condtion based on the number of results returned:

 

http://help.k2.com/onlinehelp/K2smartforms/UserGuide/1.0.7/default.htm#SF_-_Rule_Designer_-_Conditions.html%3FTocPath%3DK2%20Designer%7CRules%7C_____3

 

Regards

Badge +10

Hi,

 

One way to do this is to create a list view which displays your list and then have a list aggregator count the results.

Set it to asynchronously execute the GetList method.

Then in the form where you want to use the count, add this view but hide it and then in your rules you will have access to the controls on this hidden view and so also the count value. You can then use this in an expression.

 

Hope this helps!

Regards,

JohanL

Badge +10

Write a stored procedure and expose that throough the SQL Server Service and generate a smartobject. That would be the quickest solution.

Badge +1

Thanks all, @JohanL's suggestion has acheive the result I need..

 

@s0m3one unfortunatley the results are coming from a 3rd party Web Service so a stored procedure is not the answer to this question.

The answer marked Solution here is clever, but ridiculous.  2018, there should be a better way than to have to create an entire view.

It's 2019 now and still ridiculous. This should be bare bones functionality.

You can use expressions for semi-colon delimited values in “Data Label” in my case as below:

If ( Length ( Data Label ) = 0, 0, Length ( Data Label ) - Length ( Replace ( Data Label, ;, (Empty String) ) ) + 1 )

Reply