Skip to main content


 

Symptoms

 


I'm trying to count the number of semicolon delimited values (names in people picker field). I can do it in a workflow because the workflow wizard expression builder has the Split text function which I can then incorporate into a Count Lists function. In the K2 Designer, the Expression Builder does not have the Text Split function (while it does have the Count Lists function).
 

 

Diagnoses

 


Counting the number of values does not seem possible without the usage of a split function.
 

 

Resolution

A feature request was logged for a Split function in the K2 Designer when designing Views/Forms.

 

 

 

As a possible workaround, Javascript injection within expressions can be used to split and return the count to the effect of:

 

 

 

<script>

 

var str = "";

 

if(str) {

 

var res = str.split(";");

 

$("span;name='PickerCountDataLabel']").SFCLabel("option", "text", res.length);

 

}else {

 

$("spanename='PickerCountDataLabel']").SFCLabel("option", "text", 0);

 

}

 

</script>

 

 

 

* Javascript injection can also be used for other requirements if needed For the var str = "" part of the script, you can drag and drop the Picker control within the double quotes. This will pass the semi-colon delimited string and initialize the Javascript variable for processing. The spanfname='PickerCountDataLabel'] is a data label for returning the count of items and can be made hidden to be used within the View/Form.

 

 

 

For any future implementation that may involve or require the usage of custom Javascript, please consider the Community Forum (http://community.k2.com/) as it is a great resources for any custom development.

 

 



 

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