Can smartobject events in a process be sorted by a particular field?

  • 30 March 2015
  • 1 reply
  • 1 view

Badge +2

In a K2 process using K2 Studio I add a smart object event.  I use a List method of the smartobject to populate process instance data fields.  However, I need the TOP 1 items sorted by Date DESC.  This does not appear to be possible with a smart object event, however it is possible with the Data Event.   To use a data event however, I'd have to call the smart object once for every column I need which is terribly inefficient.

 

I'm hoping I'm totally missing something because it seems simple.   As you notice in the screen shot attached I only have 4 screens for the SO event wizard...none of which are Filter or Order By windows.  Any help is appreciated.

 

Thanks.


15105iAA8185D1083D2C77.png

1 reply

Userlevel 1
Badge +8

Hi Seth

 

This is a shortcoming of the SmartObject event. It does seem a bit odd that you can't sort or filter in the List methods.

 

One way around this is to use an Activity Destination to execute the SmartObject List method, return the ID for the row you want and then execute a smartobject read event inside the activity to return the required properties.

 

  1. Add a Default Activity to your workflow. 
  2. Select the Destination Rule and run in advanced mode
  3. Select "Plan Per Slot (No Destinations)" 
  4. Select the option "Select a list field to determine how many slots should be created"
  5. Drop your SmartObject list event in the box.
  6. Add your inputs and filter. In the return property select the ID/PK for the SmartObject.
  7. In the List Options select the "Order Results By" and choose  Descending and the Date field property.
  8. Select "Return a single item" and "First Item" options
  9. Finish the wizard
  10. Now drop a SmartObject event into the Activity
  11. Select the Read method for the same smartobject
  12. In the input mappings select the ID field and click assign
  13. In the context browser select the Function Browser -> Conversion -> To Integer.
  14. In the value for the To Integer function open the Context Browser and select Workflow Context Browser -> Activity Destination Instance -> Instance Data
  15. In the return mappings you can now map the SmartObject properties as required to any workflow fields.

Reply