cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

is it possible to replace multiple strings in one replace function?

Im running into the following problem:

 

Got a flow that creates folders in SharePoint from Accounts in CRM dynamics.

But in CRM it is possible to use special characters in the accountname.

 

When the flow gets triggered and a special character is used.

It fails because a folder name can`t contain one of these characters.

 

Example of invalid characters:

# % * : < > ? /  |

 

Im trying to replace these characters with @replace. But i dont know if its possible to replace all the characters in one function?

 

What i got now is:

 

replace(body('Account')['name'], '#, %, *, :, <, >, ?, /, |', '')

 

Please let me know if its possible

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Oke so i have been trying a lot of things and came up with a solution.

 

I created an array in the Flow with all the characters that are invalid.

Then created a foreach loop.

In this loop i let the replace function loop through all items in the array and change the string with the invalid character.

 

SO its fixed.

 

If anyone is interessted so below for the short version:

 

array.PNG

 

 

replace accountname.PNG

 

replace it with this expression:

replace(body('Account_ophalen_in_foreach')['name'], item(), '')

 

body('Account_ophalen_in_foreach')['name'] = the action to get account from dynamics and [name] is the name.

View solution in original post

13 REPLIES 13
Anonymous
Not applicable

Oke so i have been trying a lot of things and came up with a solution.

 

I created an array in the Flow with all the characters that are invalid.

Then created a foreach loop.

In this loop i let the replace function loop through all items in the array and change the string with the invalid character.

 

SO its fixed.

 

If anyone is interessted so below for the short version:

 

array.PNG

 

 

replace accountname.PNG

 

replace it with this expression:

replace(body('Account_ophalen_in_foreach')['name'], item(), '')

 

body('Account_ophalen_in_foreach')['name'] = the action to get account from dynamics and [name] is the name.

Hi,

 

This is very interesting, but I cannot make it work. I want to clear a text from all special characters.

 

When I run a loop, every time it starts from the initial text...

 

Could you post a full screen of your flow, including your loop?

 

My flow looks like this, but it does not work like I want it. It replaces each character individually - but I do not get one "clear" output text...

 

2017-11-02 09_46_14-Edit your flow _ Microsoft Flow - Internet Explorer.png

 

Thanks!

 

Anonymous
Not applicable

Hi,

 

I had this problem also.

This is because u have to include the result in your loop.

 

In my case i`m eliminating the special characters from the accountname and the subject name of a sales opportunity(SO) in CRM.

This means i have to start with getting the variable of the accountname and subject of SO.

Then start the replacement. (i edit an extra check if variable is different from the original variable and the replacement variable, if yes then it will change the name according to the new name without a special character). 

If the accountname has multiple special characters in the name, it will delete the special characters one by one)

 

When the loop starts again after a special character has already been removed, it will start looking for a new special characters with the change name of subject. i hope this is clear 🙂

 

A few printscreens from my loop:

 

(somehow i cant insert pictures) Ill post them asap.Knipsel.PNG

could post a screenshot of your expanded condition?

But if Iunderstand you correctly, in your condition you are writing back to dynamics, so when the loop starts again it works with the updated variable?

I get the idea, but it would help a lot if you could post the printscreen with expanded loops sections - the formulas are key here 🙂

 

Thanks a million!

Anonymous
Not applicable

Here they are

extended conditions.PNGnog meer.PNG

 

thanks peter,

 

As I don't use Dynamics I ended up using a Variable action instead. Initialise a varibale outside the for each and setting it to the initial value target output converted to text in this cse), then in the loop, set the variable with the upated value.

Capture.PNG

 

this works great if you want to replace the text with the same value (or in this case remove it) but I'm wondering if instead of an array you could use a json, where you find the 'key' then update it with the value.

Simon, could you please post the formula you have in replace(...) ? If I understand well, I need to refer to replace text in the 'textfeed' variable, but not really sure how to refer to content of this variable?

Thanks Peter for initial solution, and thanks Simon for your printscreens. I managed to figure this out also for my flow.

 

For anyone who is interested, here are the 2 formulas you need:

  • createArray('&','_',',','.',';',':','/','"','"','!','@','$','%','^','+','=','\','|','<','>','{','}')
  • replace(Variables('textfeed'),item(),'')

And also the printscreens of my solution.

2017-11-20 13_54_52-Edit your flow _ Microsoft Flow 1.png

 

2017-11-20 13_56_01-Edit your flow _ Microsoft Flow 2.png

 

 

MichaelS66
Advocate I
Advocate I

You can use replace within replace. I used this to remove illegal character in email subject. Not pretty but it works.

replace(replace(replace(replace(replace(replace(replace(replace(replace(triggerBody()?['Subject'],':',''),'%',''),'#',''),'*',''),'<',''),'>',''),'?',''),'/',''),'"','')

hi,

 

I've tried the multiple replace function since 1 hour but without found the exact syntax. Thank you !

@MichaelS66,

 

can you please provide more details like how to use the function because, In my scenario i'm calling Flow From PowerApps and ParseJSOn is having an error below:

Flow: Can you mention whwere to use the function on flow

Step1: PowerApps

Step2: ParseJson

Step3:Compose

Step4:Create File

Step5: Respond To PowerApps

InvalidJSON. The 'content' property of actions of type 'ParseJson' must be valid JSON. The provided value

 

I'm not sure whether to use the function on a button from PowerApp or to use it in my Flow. Can you please provide more details.

 

Thanks,

MK1

phmacena
Regular Visitor

In this following link I found the most easy way to solve this problem
Just follow the steps 😄 

https://www.alanps1.io/power-platform/flow/flow-stripping-unwanted-characters-or-special-characters-...

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (3,353)