Interface Date Field input customization

Within the Appian interface, the date field typically accepts dates separated by a forward slash ("/"). However, in our use case, there are scenarios where we need to support dates separated by a hyphen ("-") or a pipe ("|"). To accommodate this requirement, I’ve written the following piece of code

a!localVariables(
  local!onlyNumbers: cleanwith("1.22.1957", "1234567890"),
  local!length: len(local!onlyNumbers),
  if(local!length = 8,
  concat(left(local!onlyNumbers, 2), "/", mid(local!onlyNumbers, 3, 2), "/", right(local!onlyNumbers, 4)),
  if(local!length = 7,
  concat("0", left(local!onlyNumbers, 1), "/", mid(local!onlyNumbers, 2, 2), "/", right(local!onlyNumbers, 4)),
  null
  )
  ))

It seems that the Appian interface is not executing the logic as expected, and the error still persists.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Try below sample interface code..

    a!localVariables(
      local!dateInput: "",
      local!formattedDate: if(
        isnull(local!dateInput),
        null,
        a!localVariables(
          local!separator: if(
            find("-", local!dateInput) > 0, "-",
            if(find("|", local!dateInput) > 0, "|",
            if(find(".", local!dateInput) > 0, ".", "/"))
          ),
          local!parts: split(local!dateInput, local!separator),
          if(
            length(local!parts) = 3,
            concat(
              text(tointeger(local!parts[1]), "00"), "/",
              text(tointeger(local!parts[2]), "00"), "/",
              local!parts[3]
            ),
            "Invalid format"
          )
        )
      ),
      {
        a!textField(
          label: "Enter Date",
          placeholder: "MM-DD-YYYY or MM.DD.YYYY or MM|DD|YYYY",
          value: local!dateInput,
          saveInto: local!dateInput
        ),
        a!textField(
          label: "Formatted Date",
          value: local!formattedDate,
          readOnly: true
        )
      }
    )

Reply
  • 0
    Certified Lead Developer

    Try below sample interface code..

    a!localVariables(
      local!dateInput: "",
      local!formattedDate: if(
        isnull(local!dateInput),
        null,
        a!localVariables(
          local!separator: if(
            find("-", local!dateInput) > 0, "-",
            if(find("|", local!dateInput) > 0, "|",
            if(find(".", local!dateInput) > 0, ".", "/"))
          ),
          local!parts: split(local!dateInput, local!separator),
          if(
            length(local!parts) = 3,
            concat(
              text(tointeger(local!parts[1]), "00"), "/",
              text(tointeger(local!parts[2]), "00"), "/",
              local!parts[3]
            ),
            "Invalid format"
          )
        )
      ),
      {
        a!textField(
          label: "Enter Date",
          placeholder: "MM-DD-YYYY or MM.DD.YYYY or MM|DD|YYYY",
          value: local!dateInput,
          saveInto: local!dateInput
        ),
        a!textField(
          label: "Formatted Date",
          value: local!formattedDate,
          readOnly: true
        )
      }
    )

Children
No Data