Velocity scripting and leading spaces

Hi all,
Hoping that someone can find the error in my script that is putting in leading spaces:

Input : 7200001-C;7200002-G;7200003-L
Output : " 7200001;7200002" (3 spaces)
Input : 7200002-C
Output : " 720000" (1 space)

#set($result='')
#set($values=$inputString.split(';'))
#foreach($value in $values)
#if($value.endsWith('-C') || $value.endsWith('-G'))
#set($numberPart=$value.substring(0, 7).trim())
#if($result=='')
#set($result=$numberPart)
#else
#set($result=$result + ';' + $numberPart)
#end
#end
#end
$result.trim()

Where else can I put a ‘trim’ function?
Thanks

Hey Phil,
I don’t know where those spaces are coming from, but I would suggest using the Replace primitive here instead. Some regex to select any non-numeric, non-semicolon characters and replace them with '' should do the trick.

1 Like

Hi @phil_awlings ,

#set($values = $inputString.split(';'))
#foreach($value in $values)
  #if($value.endsWith('-C') || $value.endsWith('-G'))
    #set($numberPart = $value.substring(0, 7).trim())
    #if($result == '')
      #set($result = $numberPart)
    #else
      #set($result = $result + ';' + $numberPart)
    #end
  #end
#end
#set($result = $result.trim())
$result

could you please try this?

1 Like

Still 3 leading spaces when applying it the AD attribute ext.att4:
image
image

Weirdly, the leading spaces aren’t present on the identity preview…
image
and this is the account CREATE transform, just in case.

        {
            "name": "extensionAttribute4",
            "transform": {
                "type": "identityAttribute",
                "attributes": {
                    "name": "attributeName"
                }
            },
            "attributes": {},
            "isRequired": false,
            "type": "string",
            "isMultiValued": false
        },

EDIT: Tried replacing the final trim with a replaceAll, and I am still getting leading spaces:

...($result = $result.replaceAll(' ',''))$result"

In case , could you please check once if ISC is sending those values with spaces or without spaces in plan?

1 Like

Solution:
Stuck a ‘trim’ function on the CREATE profile which works:

        {
            "name": "extensionAttribute4",
            "transform": {
                "type": "trim",
                "attributes": {
                    "input": {
                        "type": "static",
                        "attributes": {
                            "value": {
                                "type": "identityAttribute",
                                "attributes": {
                                    "name": "attributeName"
                                }
                            }
                        }
                    }
                }
            },
            "attributes": {},
            "isRequired": false,
            "type": "string",
            "isMultiValued": false
        }

But doesn’t really explain why it was being sent in the first place.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.