AddedRemoved from multi select

From SMTX Wiki
Jump to navigation Jump to search

When using a multi select list, it sometimes occurs that you want to pre-select items and track which of these items have been removed and which items have been added. With the NCALC functions displayed below you can get a list of items added and removed. Just like in the example screenshot below:

The NCALC fields look like this:

   REMOVED: foreachstring('#REPLACE-FORMFIELD-formname||hidAlreadyInstalled||#','||','IIF(INDEXOF(\'#REPLACE-FORMFIELD-formname||hidCurrentSWSelection||#\',\'{0}\')=-1,\'{0},\',\'\')','')
   ADDED: foreachstring('#REPLACE-FORMFIELD-formname||hidCurrentSWSelection||#','||','IIF(INDEXOF(\'#REPLACE-FORMFIELD-formname||hidAlreadyInstalled||#\',\'{0}\')=-1,\'{0},\',\'\')','')

Explained The ForEachString function is used to break up the list with already installed items. For each occurence in that list, the IIF function checks if it is mentioned in the current selection list. When mentioned, it should be ignored, if not mentioned, there is a difference and the occurence is included in the Removed field. The Added and Removed fields are identical, except that the fields OLD/NEW are switched. You may want to additionally take care of the last , in the result string.