[✅ Solution] Automation to find/replace variables

I need to figure out the right calculation script to run a workflow that essentially looks for certain placeholders within a multi line text field ‘template’ and then replaces those with the defined variables from my current item in Tape.

For an example, I used to use a PHP variable as follows in Globiflow:

str_replace("[Company Phone]",[(Variable) senderPhone],
str_replace("[Lead Manager Name]",[(Variable) LMFName],
str_replace("[Address - Street Only]",[(Variable) streetaddress],
str_replace("[Full Address]",[(Variable) fulladdress],
str_replace("[Acquisition Manager Name]",[(Variable) AMFName],
str_replace("[Phone Number]",[(Variable) txtPhone],
strip_tags_gf([(Ref Message Template) Text Message Body])))))))

I tried various approaches from some google searching to accomplish this in Javascript but I have not found a good working answer yet.
I know this will be a simple answer for somebody, but my limited javascript skills have failed me here. Thanks in advance for any guidance here.

1 Like

Hi @CarsonRedCliffLabs,

you should be able to use the default replace method for JavaScript strings, such as:

const result = title_field_value.replace('some placeholder', 'string to use as replacement')

… which will replace the first occurrence of some placeholder inside your string. If you want to replace all occurences instead, you can use the moden JS feature replaceAll instead:

const result = title_field_value.replaceAll('some placeholder', 'string to use as replacement')

You can then work with the resulting variable, reassign or pass it to following steps.

Let me know how that works!

Cheers
Tim

Thank you Tim. I knew you’d come through for me!
I was able to get this working, I ended up using something similar to the following:

This gives me what I needed!

1 Like