Skip to main content

I have a field (text string) that has 20 possible options, i.e. below

 

"NO_CREDIT_FILE"
"INSUFFICIENT_NUMBER_OF_CREDIT_REFERENCES_PROVIDED"
"UNACCEPTABLE_TYPE_OF_CREDIT_REFERENCES_PROVIDED"
"LIMITED_CREDIT_EXPERIENCE"
"POOR_CREDIT_PERFORMANCE_WITH_US"
"UNABLE_TO_VERIFY_CREDIT_REFERENCES"
"GARNISHMENT_OR_ATTACHMENT"
"FORECLOSURE_OR_REPOSSESSION"

 

How can I format the string to remove underscores and properly capitalize . i.e. “NO_CREDIT_FILE” would be No Credit File

 

I thought of using Paths but Paths is limited to only 10 paths and I have 20. I would prefer not to make multiple zaps


 

Hi there @Iggy,

Welcome to the Community! 🎉

You might have to use Code by Zapier for this to be possible.

I used the Run Javascript event and “Generate with AI” to help me get the correct code and here’s the result:

5698afa1b1769192ac612580061ed864.png
(view larger)

c8d0504de9fa1c7e38c0b80aeefd4036.png
(view larger)

Here’s the code

// Check if inputData is defined and contains the original_text field

if (inputData && inputData.original_text) {

    const inputText = inputData.original_text;

    

    // Function to format text by removing underscores and converting to title case

    function formatText(text) {

        return text

            .replace(/_/g, ' ') // Replace underscores with spaces

            .toLowerCase() // Convert all characters to lowercase

            .split(' ') // Split the text into an array of words

            .map(word => word.charAt(0).toUpperCase() + word.slice(1)) // Capitalize first letter of each word

            .join(' '); // Join the array back into a string

    }

    

    const formattedText = formatText(inputText);

    

    return { formatted_text: formattedText };

} else {

    return { error: "Input text is undefined or empty." };

}

 

Hopefully, this helps!


Hi @Iggy 

Try the concept of a Lookup Table:

 


@Iggy 

Here’s another approach using Formatter steps

  1. Action: Formatter > Text > Split
    1. Separator: _
    2. Segment Index: All (as Line Items)
  2. Action: Formatter > Text > Titlecase
  3. Action: Formatter >. Utilities > Line Items to Text
    1. Separator: r:space:]

 

 

 

 


Reply