SOLVED

Logic app search replace function usage example?

%3CLINGO-SUB%20id%3D%22lingo-sub-3038904%22%20slang%3D%22en-US%22%3ELogic%20app%20search%20replace%20function%20usage%20example%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3038904%22%20slang%3D%22en-US%22%3ECan%20someone%20please%20give%20me%20an%20example%20function%20for%20search%20and%20replace%3F%3CBR%20%2F%3EI'm%20using%20html%20in%20the%20sentinel%20'add%20comments'%20operator%20and%20I'm%20seeing%20lots%20of%20%5Cn%20characters.%3CBR%20%2F%3EI%20want%20to%20remove%20them%20all%20so%20they%20don't%20write%20line%20feeds%20to%20the%20output%20and%20mess%20up%20my%20html%20markup.%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3039550%22%20slang%3D%22en-US%22%3ERe%3A%20Logic%20app%20search%20replace%20function%20usage%20example%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3039550%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F660532%22%20target%3D%22_blank%22%3E%40cmaneiro%3C%2FA%3E%26nbsp%3BI%20don't%20suppose%20you've%20ever%20tried%20to%20embed%20the%20'playbook%20RUN'%20button%20into%20html%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'd%20like%20to%20know%20the%20structure%20of%20the%20url%2C%20or%20if%20it's%20possible%20to%20use%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20expect%20it's%20a%20POST%20call%2C%20so%20maybe%20not..%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22bobsyouruncle_0-1639599197105.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F334065iA94E3685AA8043CB%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22bobsyouruncle_0-1639599197105.png%22%20alt%3D%22bobsyouruncle_0-1639599197105.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Eeg.%20I%20know%20the%20basic%20playbook%20url%20structure%20is%20this%3A%3CBR%20%2F%3E%3CSPAN%3E%2Fsubscriptions%2F%3CTENANT%3E%2FresourceGroups%2F%3CWORKSPACE%3E%2Fproviders%2FMicrosoft.Logic%2Fworkflows%2F%3CPLAYBOOK%20name%3D%22%22%3E%3C%2FPLAYBOOK%3E%3C%2FWORKSPACE%3E%3C%2FTENANT%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3EBut%20can%20you%20add%20to%20this%20url%20to%20have%20it%20run%20the%20playbook%20for%20a%20given%20Incident%20or%20alert%3F%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3039538%22%20slang%3D%22en-US%22%3ERe%3A%20Logic%20app%20search%20replace%20function%20usage%20example%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3039538%22%20slang%3D%22en-US%22%3E%3CP%3EBy%20the%20way%2C%20for%20those%20who%20doesn't%20know%2C%20you%20can%20add%20html%20markup%20to%20variable%20operators%2C%20but%20you%20can't%20add%20them%20to%20operators%20which%20have%20embedded%20text%20editors.%3C%2FP%3E%3CP%3ESo%20this%20is%20valid%20because%20set%20variable%20operators%20don't%20contain%20embedded%20text%20editors%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22bobsyouruncle_0-1639598506331.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F334062i4A2DC361593F419E%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22bobsyouruncle_0-1639598506331.png%22%20alt%3D%22bobsyouruncle_0-1639598506331.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E(%20a%20problem%20I%20was%20having%20is%20that%20all%20of%20the%20variables%20above%20automatically%20include%20a%20%5Cn%20at%20the%20end%20of%20the%20variable%2C%20so%20you%20may%20have%20to%20use%20the%20'replace'%20function%20to%20strip%20those%20out)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20you%20can't%20add%20html%20in%20here%2C%20unless%20it's%20contained%20in%20the%20variables.%3C%2FP%3E%3CP%3EHTML%20in%20the%20body%20of%20the%20editor%20will%20just%20be%20printed%20as%20text.%3C%2FP%3E%3CP%3EThe%20'IncidentComments'%20variable%20can%20contain%20html%20and%20it%20will%20be%20formatted%20correctly.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22bobsyouruncle_1-1639598549272.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F334063iE0D43FA813788286%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22bobsyouruncle_1-1639598549272.png%22%20alt%3D%22bobsyouruncle_1-1639598549272.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3039531%22%20slang%3D%22en-US%22%3ERe%3A%20Logic%20app%20search%20replace%20function%20usage%20example%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3039531%22%20slang%3D%22en-US%22%3E%3CP%3Eamazing%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F434938%22%20target%3D%22_blank%22%3E%40bobsyouruncle%3C%2FA%3E%26nbsp%3B!!!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGlad%20to%20help!!!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERegards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3039529%22%20slang%3D%22en-US%22%3ERe%3A%20Logic%20app%20search%20replace%20function%20usage%20example%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3039529%22%20slang%3D%22en-US%22%3E%3CP%3EHey%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F660532%22%20target%3D%22_blank%22%3E%40cmaneiro%3C%2FA%3E%2C%26nbsp%3Bthanks!%20that%20worked%20for%20me.%3C%2FP%3E%3CP%3ETook%20me%20a%20minute%20to%20realize%20your%20example%20was%20a%20'replace%20inside%20of%20a%20replace'%2C%20which%20was%20more%20than%20i%20needed.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20was%20able%20to%20replace%20all%20of%20the%20html%20content%20containing%20'%5Cn'%20with%20''%26nbsp%3B%20%26nbsp%3B(''%20%3D%20nothing).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20my%20solution%20was%3A%3C%2FP%3E%3CP%3E-%20collect%20all%20variables%20(which%20contain%20html%20markup)%20and%20assign%20them%20all%20to%20a%20single%20variable.%3C%2FP%3E%3CP%3E-%20replace%20all%20%5Cn%20values%20with%20nothing.%3C%2FP%3E%3CP%3E-%20use%20the%20cleaned%20up%20variable%20in%20my%20Sentinel%20Incident%20comments.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22bobsyouruncle_1-1639597787077.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F334056i8962981D954A87EA%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22bobsyouruncle_1-1639597787077.png%22%20alt%3D%22bobsyouruncle_1-1639597787077.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20result%20is%20a%20much%20better%20formatted%20html%20with%20only%20one%20line%20feed%20between%20the%20text%20body%20and%20the%20table%20(before%20there%20were%208%20linefeeds!)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22bobsyouruncle_3-1639597903231.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F334058i929970248DF93A82%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22bobsyouruncle_3-1639597903231.png%22%20alt%3D%22bobsyouruncle_3-1639597903231.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3038979%22%20slang%3D%22en-US%22%3ERe%3A%20Logic%20app%20search%20replace%20function%20usage%20example%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3038979%22%20slang%3D%22en-US%22%3E%3CP%3Ehi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F434938%22%20target%3D%22_blank%22%3E%40bobsyouruncle%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENot%20sure%20if%20it's%20the%20same%2C%20but%2C%20I've%20feced%20something%20similar%20with%20an%20HTML%20table%20where%20I%20wanted%20to%20include%20a%20hyper%20link%20using%20%3CSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3C%2FA%3E%3C%2FSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20and%20Logic%20App%20replaced%20those%20chars.%26nbsp%3B%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%20I%20did%20was%20process%20the%20HTML%20content%20before%20using%20it%20(Send%20Email)%20as%20an%20expression%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSTRONG%3Ereplace(replace(variables('email_html')%2C%26nbsp%3B'%26amp%3Blt%3B'%2C%26nbsp%3B'%26lt%3B')%2C%26nbsp%3B'%26amp%3Bgt%3B'%2C%26nbsp%3B'%26gt%3B')%3C%2FSTRONG%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EMaybe%20my%20scenario%20is%20simplier%20than%20the%20one%20you%20have%20but%20hope%20it%20helps%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
Contributor
Can someone please give me an example function for search and replace?
I'm using html in the sentinel 'add comments' operator and I'm seeing lots of \n characters.
I want to remove them all so they don't write line feeds to the output and mess up my html markup.

Thank you.
5 Replies
best response confirmed by cmaneiro (Microsoft)
Solution

hi @bobsyouruncle 

 

Not sure if it's the same, but, I've feced something similar with an HTML table where I wanted to include a hyper link using <a href> and Logic App replaced those chars. 

 

What I did was process the HTML content before using it (Send Email) as an expression 

replace(replace(variables('email_html'), '&lt;', '<'), '&gt;', '>')
 
Maybe my scenario is simplier than the one you have but hope it helps

Hey @cmaneiro, thanks! that worked for me.

Took me a minute to realize your example was a 'replace inside of a replace', which was more than i needed.

 

I was able to replace all of the html content containing '\n' with ''   ('' = nothing).

 

So my solution was:

- collect all variables (which contain html markup) and assign them all to a single variable.

- replace all \n values with nothing.

- use the cleaned up variable in my Sentinel Incident comments.

bobsyouruncle_1-1639597787077.png

 

The result is a much better formatted html with only one line feed between the text body and the table (before there were 8 linefeeds!)

 

bobsyouruncle_3-1639597903231.png

 

amazing @bobsyouruncle !!!

 

Glad to help!!!

 

Regards

By the way, for those who doesn't know, you can add html markup to variable operators, but you can't add them to operators which have embedded text editors.

So this is valid because set variable operators don't contain embedded text editors:

bobsyouruncle_0-1639598506331.png

( a problem I was having is that all of the variables above automatically include a \n at the end of the variable, so you may have to use the 'replace' function to strip those out)

 

But you can't add html in here, unless it's contained in the variables.

HTML in the body of the editor will just be printed as text.

The 'IncidentComments' variable can contain html and it will be formatted correctly.

bobsyouruncle_1-1639598549272.png

 

 



@cmaneiro I don't suppose you've ever tried to embed the 'playbook RUN' button into html?

 

I'd like to know the structure of the url, or if it's possible to use it.

 

I expect it's a POST call, so maybe not..

 

bobsyouruncle_0-1639599197105.png

eg. I know the basic playbook url structure is this:
/subscriptions/<tenant>/resourceGroups/<workspace>/providers/Microsoft.Logic/workflows/<playbook name>

But can you add to this url to have it run the playbook for a given Incident or alert?