Creating substring in Variables for Workflows

:bangbang: Please be sure you’ve read the docs and API specs before asking for help. Also, please be sure you’ve searched the forum for your answer before you create a new topic.

I am creating a substring variable to capture the “FirstName LastName” that comes in the userDN of the identity. Need to display it in the email, when I execute the workflow I get $previousname instead of the value.

{
  "name": "previousname",
  "description": "previousname",
  "transforms": [
    {
      "id": "sp:transform:substring:string",
      "input": {
        "start": 2,
        "length": 20
      }
    }
  ],
  "variableA.$": "$.trigger.changes[?(@.attribute == \"userdn\")].oldValue"
}

Hi @KirtiSikarwar ,

How are you referring to the variable? If you are using it for any comparison, you can refer to it using $.defineVariable.previousname

If you are using it in sending email, you can declare the Templating Context as below -
{"variableA.$":"$.defineVariable.previousname"} and then use the VariableA in the email body or subject using ${variableA}

Hi @KirtiSikarwar,

Is your define variable work ?

If not you cant use replace in your define variable.
Assuming you have dn like this : cn=firstname lastname,DC=test,DC=com

In define variable operator for your new variable previousname you can replace in sequence $.trigger.changes[?(@.attribute == "userdn")].oldValue

DC=test,DC=com by ,
cn=  by ,

Note : in workflow i don’t know how to replace a value per empty. That’s why i purpose to replace by ,

in ouput you have ,firstname lastname,

you can then substring into a new variable for eleminating , or in your email template you can replace , per “” after define {“VariablePreviousname$”:“$.defineVariable.previousname”} as @shaileeM say.

for example in your template :
you can do :
#set($newVariablePreviousName=$VariablePreviousname.replace(“,”,“”)).

That’s the quick solution that i found but will test other solution and come back to you.

1 Like

Thanks @shaileeM this works. I realised I wasnt calling the variable correctly in the email. The issue I am stuck with currently is the length I am defining for the variable as it could be more than 20 characters. I only want to capture the “FirstName LastName” from the DN. Is there a better way?

Hi @KirtiSikarwar , I agree with @baoussounda

Assuming you have userdn like this : “cn=firstname lastname,DC=test,DC=com”, I suggest you don’t need to use defined variable such as “previousname”.

You can declare the Templating Context in the “Send Email” action as below -

{"variableA.$":"$.trigger.changes[?(@.attribute == \"userdn\")].oldValue"}

and then use the following in the email body or subject using to fetch the “firstname lastname” string directly -

#set ($myArray = $variableA.split(',')[0].split('='))
$myArray[1]

This should help you extract $myArray[1] as “firstname lastname”

Let me know how it goes.

Best, Shailee

This works perfect. I no longer required the index and substring variables.

1 Like

Hi @KirtiSikarwar Glad it helped!

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