ListLimitBasedOnValue

From SMTX Wiki
Jump to navigation Jump to search

A formfield contains a comma seperated list of allowed values. another formfield showing a datastore parameter should be dynamically filtered based on the values in the comma seperated list.

For example: - Location A allows order types 1,2 and 3 - Location B allows order types 3,4 and 5

When Location B is selected, the list with order types should only display the ordertypes with ID 3, 4 and 5.

The solution is found in the creation of X hidden fields. X equals the maximum number of values in the comma seperated list. Each hidden field will contain 1 value and all hidden fields are used to set the condition in the dynamic filters on the datastore list.

The first value from the comma seperated list is retrieved like this:

indexof('#REPLACE-FORMFIELD-Filterandfieldtest||location||Available subtypes#', ',') == -1 ?
'#REPLACE-FORMFIELD-Filterandfieldtest||location||Available subtypes#' :
substring('#REPLACE-FORMFIELD-Filterandfieldtest||location||Available subtypes#', 0,
indexof('#REPLACE-FORMFIELD-Filterandfieldtest||location||Available subtypes#', ','))

Now store the remaining string in another hidden field, like this:

substring('#REPLACE-FORMFIELD-Filterandfieldtest||location||Available subtypes#',
indexof('#REPLACE-FORMFIELD-Filterandfieldtest||location||Available subtypes#', ',')+1)

The second hidden field, should contain the second value from the list and is defined like this:

indexof('#REPLACE-FORMFIELD-Filterandfieldtest||subtypeid1rest||#', ',') == -1 ? 
'#REPLACE-FORMFIELD-Filterandfieldtest||subtypeid1rest||#' :
substring('#REPLACE-FORMFIELD-Filterandfieldtest||subtypeid1rest||#',0 ,
indexof('#REPLACE-FORMFIELD-Filterandfieldtest||subtypeid1rest||#', ','))

After this, the remaining string is stored again, as explained previously. For every remaining hidden field the similar function as above should be used.