stringpower-automatetoupper

Capitalize first letters string of words and add word to string


I working a power automate flow and I've been struggling for quite a while to create a variable which I need to populate "County Name" in my word template. This flow allows a County staff member to fill out a form and then those MS Form responses dynamically populate in a word template. All of this works well but I'm struggling to create a variable which would populate "County Name" in my word template. I need the variable (dynamic content) to be able to capitalize the response from the MS Form

I need the dynamic content to be able to capitalize the name of County, so capitalize first word and second word. Example: "Washington County". I also need the variable to recognize when someone just puts "Washington" in the MS Form, instead of "Washington County", and then add County to the word template. I've tried quite a few combinations with toUpper and append string and not able to quite figure it out. Can anyone help?

enter image description here enter image description here


Solution

  • My suggestion, look at using the Advanced Data Operations connector.

    There are a few ways to achieve what you're wanting but the easiest way is by using the Transform operation.

    There are over 100 built-in functions that can be made use of through the framework and one of them is the Proper function.

    It will also allow you to concatenate strings at the same time. However, that process seems quite clunky for your requirement given how do you know if County should be added? I'll leave that with you though.

    https://www.statesolutions.com.au/custom-functions/

    (On the String tab, scroll down to the Proper function)

    This is a basic example ...

    Flow

    You can see I've initialised a variable with the relevant value.

    I've then configured the transform function (it takes an array of objects) to take in your data along with a transformation definition.

    That definition runs a set of functions to get the result you need. Rather than checking for County at the end, I just add it and then replace County County with County.

    You can also see the Proper function in there, that's the key part that uppercases each word.

    This will be made easier in future as there is an Evaluate operation coming and that will allow you to do it in much simpler terms.

    https://www.statesolutions.com.au/c-script-evaluate/

    That's looking to drop by the end of this month but is available now via the HTTP operation.

    Result (with "county" in the provided value)

    Result 1

    Result (without "county" in the provided value)

    Result 2