Flow Designer - Transform Function - Replace string not working on HTML field type

Ashby0003
Tera Guru

Hi, 

I am working on a payload for an API call and need to add an exit character before every ' (apostrophe).

I'm using flow designer and successfully used the "replace string" transform function for string fields but now am working on doing the same thing for a HTML field.

so for an example. 

"<p>testing thing's is so much fun. Thankfully that's Randy's job </p>"
 
I need to dynamically add a \ in front of every '
 
"<p>testing thing\'s is so much fun. Thankfully that\'s Randy\'s job </p>"
 
Unfortunately the built in "transform function" doesn't seem to be working with HTML fields.
 
Any ideas?
8 REPLIES 8

Ben28
Tera Contributor

Hi @CStaples yes, got it working in the end after some fiddling around with code. Wasn't the cleanest code, but it worked, and we went live with the story just before Christmas. 🙂

CStaples
Tera Contributor

@Ben28 Thanks Ben!  I'd be very curious to hear about your solution through Flow Designer.  I have personally been working on piecing this whole situation together.  Currently the two challenges I'm working with:

1) The Meeting_Notes field getting overwritten by the OOB Script Include: CABAgendaItemSNC
2) The HTML tags getting added to the Meeting_Notes field.

Ben28
Tera Contributor
So I set the flow to trigger once, when state changes from RCA to Fix in Progress. I wanted the Fix Notes to create a new general PTASK for tracking the fix implementation. I took the HTML fix notes, and created a plaintext PTASK, removing the html, the extra line breaks and special characters.
Ben28_0-1738870205512.png
 

 

var ptaskfixstatement = "This Problem Task (PTASK) is for tracking the implementation of Corrective and Preventive Actions (CAPA) identified in the Root Cause Analysis (RCA).\n" +
"The task may be reassigned to the team or individual responsible for executing the CAPA actions.\n" +
"If needed, additional PTASKs can be created to support further actions.\n";
var htmlString = fd_data.trigger.current.fix_notes;
const plainText = decodeHTML(htmlString);
combinedText = ptaskfixstatement + plainText;
return combinedText;

function decodeHTML(str) {
    var a = str.replace(/<br\s*\/?>|<p\s*\/?>|<\/?(ul|ol|li)\s*\/?>/gi, '\n'); //Retain line breaks & replace bullet & number lists with new line.
    var b = a.replace(/<\/?[^>]+(>|$)/g, ""); //Remove tags
    var c = b.replace(/&amp;/g, '&'); //Retain any ampersands that are just ampersands
    var d = c.replace(/\n+/g, '\n'); // combine multiple line breaks into 1.
    return d.replace(/&#(\d+);/g, function(match, dec) {
        return String.fromCharCode(dec); //Returns the special character from the decimal code representation and returns the entire decoded string.
    });
}

 

CStaples
Tera Contributor

Thanks for sharing Ben!  I think I'm going to continue the course with the Flow Data Transformation Pill rather than a scripted approach.  I appreciate having this as reference in case I run into any walls.