Power Automate issue - invalid filename issue

Hi,

I am attempting to use a replace function in power automate to remove invalid characters from the name field so the SharePoint file will save. Below is the formula I created. I originally only had the function replacing the comma and the period, but the output for Bob Smith, Jr. outputs as "Bob Smith Jr \\r". I added to the function to replace the backslash but it isn't replacing it.

replace(replace(replace(outputs('Get_a_constituent')?['body/name'], ',', ''), '.', ''), '\\', '')

d35c3b0aba706e8b9c69393343f3d737-huge-im
showing raw output

I'm wondering if the backslash isn't actually part of the name, but I'm not sure where it is coming from.

If anyone can point me in the right direction, I would appreciate it.

Comments

  • Hey @Hallie Guiseppe, the \\r is a special character that's returned for a carriage return (new line). Instead of doing Replace('\\') try Replace with decodeUriComponent('%0A')

  • @Hallie Guiseppe, actually, after testing, this is the best way:

    decodeUriComponent(

    replace(

    encodeUriComponent(variables('test')),

    '%0A',

    ' '

    )

    )

    The variables('test') is just the output that has line breaks in it.

  • Hallie Guiseppe
    Hallie Guiseppe Community All-Star
    Sixth Anniversary Kudos 5 Name Dropper Participant

    @Matt Thacker Thank you so much for pointing me in the right direction! I ended up basically with what you suggested. (I didn't see your second post until I logged back in to follow up with what I built) I had to break it into two actions. One to encode the name and another to replace. I couldn't get it to work when I had them in the same action.

    Also, I found that MS recommends using “uricomponent()” rather than “encodeUriComponent()” although I'm not sure why. The two resources I found most useful are the Reference Guide and the HTML URL Encoding Reference.

    Enode function= uriComponent(outputs('Get_a_constituent')?['body/name'])

    Replace invalid Characters= replace(replace(replace(outputs('encode_Constituent_Name'),'%20',' '),'%2C',''),'%0D','')

    e4ee9496b10225dc2451e1f8c971cd6a-huge-im
    compose actions to convert name into save format