How to replace/substitute placeholders with values in a string using either reduce or forEach?

Certified Senior Developer

Hi All,

We have small requirement like need to replace/substitute the places holders in string with values.

a!localVariables(
  local!template: "Hello, {name}! Welcome to {place}.",
  local!placeholders: {
    "name": "John",
    "place": "Appian"
  },

  a!forEach(
    items: a!keys(local!placeholders),
    expression: a!localVariables(
      local!placeholder: fv!item,
      local!value: local!placeholders[local!placeholder],
      local!template: substitute(
        local!template,
        "{" & local!placeholder & "}",
        local!value
      ),
      local!template
    )
  )
)

which returns the following out put like 

List of Text String - 2 items

    • "Hello, John! Welcome to {place}."(Text)
        • "Hello, {name}! Welcome to Appian."(Text)

        Need to replaced all of them in single string with some sequential manner.

        Your expertise is helpful to solve.

        Thanks in advance.

          Discussion posts and replies are publicly visible