Guidance on complex VT logic

Looking for guidance if the below logic is possible within ISC transforms and what my problem might be below.

My VT logic is:

#if($persona != 'Student - MedEd' && $persona != 'Student - CPDP' && $psTitle != 'none')$psTitle

#elseif(($persona == 'Student - MedEd' || $persona == 'Student - CPDP') && $studentTitle != 'none')

#set($cleanedStudentTitle = $studentTitle.replaceAll('\\{\\}', '').replaceAll('\\}\\{', ', ').replaceAll('[{}]', ''))

#set($titleArray = $cleanedStudentTitle.split(', '))#set($titleSet = [])#foreach($title in $titleArray)

#if(!$titleSet.contains($title))#set($dummy = $titleSet.add($title))
#end
#end
#set($deduplicatedStudentTitle = $titleSet.join(', '))$deduplicatedStudentTitle#end"

The first set statement shows what I was writing out if the conditions were met. This all works if I only go up to the first set statement.

I run into errors once I try to do the additional logic used to remove duplicate values.

Example input:

{Sales Engineer}{Sales Engineer}{}{Interim Sales Manager}

Expected output would be:
Sales Engineer, Interim Sales Manager

It removes empty fields, replaces “}{” with ", " characters to allow splitting and an array to remove duplicates.

thanks,
Fred

I am seeing your problem in line 3. I guess you cannot use .replaceAll three there. Use .replaceAll three times.

#set($cleanedStudentTitle = $studentTitle.replaceAll('\\{\\}', '')
#set($cleanedStudentTitle = $studentTitle.replaceAll('\\}\\{', ', ')
#set($cleanedStudentTitle = $studentTitle.replaceAll('[{}]', '')

Let me know if that works.

1 Like

Below is the logic I was able to get to work.

#set($uniqueTitles = [])#if($persona != 'Student - MedEd' && $persona != 'Student - CPDP' && $psTitle != 'none')$psTitle

#elseif(($persona == 'Student - MedEd' || $persona == 'Student - CPDP') && $studentTitle != 'none')

#set($studentTitle = $studentTitle.replaceAll('\\{\\}', '').replaceAll('\\}\\{', ', ').replaceAll('[{}]','').split(', '))

#foreach($title in $studentTitle)
  #if(!$uniqueTitles.contains($title))
    #set($ignore = $uniqueTitles.add($title))
    #end
  #end
#set($output = $uniqueTitles.toString().replace('[', '').replace(']', ''))$output
#end
1 Like