How to replace text output on in a snippet with conditional values upon the same output

Trying to replace the capitalized word, "There" with the uncapitalized "there" in a Gmail email. When the snippet shows its preview, I want it to kinda know that the code above outputted "There" and I want it to automatically be changed in that case, to "there" and I'm failing miserably. Please don't laugh about this attempt.

Screenshot 2023-05-02 at 12.16.42 PM

@anon25555005 nothing to laugh at, that's a good attempt!

Depending on exactly how you want it to output, there's a few ways you could approach it. Here's one example:

Hello {GmailName=replace(filter(split(proper({gmail-firstname: default=there; type=multiple}), " "), x -> x<>"And"), "There", "there")}{=join(GmailName, "BLAZE_AND")}

You read formulas that have multiple functions from the inside out, so this is:

  • applying to the proper function to the gmail first names
  • splitting those into a list (can't use the Gmail firstname list type because it treats unknowns as blanks and also doesn't allow for defaults)
  • filtering out the entry for "And" (which is automatically added when using the type=multiple on the Gmail firstname)
  • replacing any instances of "There" with "there"
  • then uses join with the BLAZE_AND syntax to write out that list as a string in "a, b, c, and d" format

Doing this results in some potentially weirdly phrased outputs like "Hi Walter and there", so you may need to fine-tune it to do exactly what you want.

(note: Gmail commands don't work in the community so disregard the error, if you copy that to your account it'll work fine)

2 Likes

If you're just doing this for a single first name at a time, you could instead do it this way:

Hello {GmailName={gmail-firstname: default=there}}{if: proper(GmailName)="There"}there{else}{=proper(GmailName)}{endif}

2 Likes

Thank you! You are a gentlemxn and a scholar. Props for understanding my poorly asked initial question!

2 Likes