Monday, July 30, 2018

How to convert string to URL friendly string with Microsoft Flow

I was working on a project to automate Office 365 Group creation using Microsoft Flow and a custom system. When trying to convert the title from another system , which could include !@#$%^? and a bunch of other characters, I had to find a way to convert that string, into an URL friendly string with Microsoft Flow,  At the time of writing this blog, there was no regex support in Microsoft Flow, so we need to get a bit more creative!

How to convert string to URL friendly string with Microsoft Flow

One function that we have access to in Microsoft Flow, is the replace function. The Replace function allows you to replace a character by another one, in our case, we need to replace for example a hashtag (#) by nothing! While this is done one character at a time, you can also nest them, so while not pretty, you would have all the info in a single function. In the example below, I strip the Title dynamic property of the Trigger of the following characters: : % # * < > ? / ” @ & = / ; |) \ [ ] ~ { } ^ ! , .   

PS: The widget below has a “copy” button in the toolbar to make sure you copy it all!

replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(triggerBody()?['Title'],':',''),'%',''),'#',''),'*',''),'<',''),'>',''),'?',''),'/',''),'"',''),'"',''),'@',''),'&',''),'=',''),'/',''),';',''),'|',''),'\',''),'[',''),']',''),'~',''),'{',''),'}',''),'^',''),'!',''),',',''),'.',''

I have created a quick Flow over here in a completely different system, just to show you the results! First, let’s create the simple Flow, three easy steps – Trigger – Create a Variable with the Friendly URL (Optional) – Update the Item

How to convert string to URL friendly string with Microsoft Flow

The value of the Variable is the formula we have above and remember to update it with the actual string that you want fixed! If you copy paste it from the blog, it will fix the Title property of the Trigger.

How to convert string to URL friendly string with Microsoft Flow

And here is the result:

How to convert string to URL friendly string with Microsoft Flow

As you see, my previous example did not take out the spaces, if you want a formula that takes out the spaces, you can use the following one!

replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(triggerBody()?['Title'],':',''),'%',''),'#',''),'*',''),'<',''),'>',''),'?',''),'/',''),'"',''),'"',''),'@',''),'&',''),'=',''),'/',''),';',''),'|',''),'\',''),'[',''),']',''),'~',''),'{',''),'}',''),'^',''),'!',''),',',''),'.',''),' ','')

Here is the result on the second item:

How to convert string to URL friendly string with Microsoft Flow

Leave a comment and don’t forget to like the Absolute SharePoint Blog Page   on Facebook and to follow me on Twitter here  for the latest news and technical articles on SharePoint.  I am also a Pluralsight author, and you can view all the courses I created on my author page.

The post How to convert string to URL friendly string with Microsoft Flow appeared first on Absolute SharePoint Blog by Vlad Catrinescu.


by Vlad Catrinescu via Absolute SharePoint Blog by Vlad Catrinescu

No comments:

Post a Comment