Convert Rich-Text pill in Flow Designer to plain text

BrunoAguiar428
Tera Expert

Hi Servicenow Community,

 

I am working on a flow that dumps the content of various "pills" (variables) into the description field. The issue is that they are being copied into the description field with HTML tags since they are set up as rich-text boxes on the record producer/form. 

 

Is there a function I can use that would convert the rich-text to plain text? I looked around but there doesn't seem to be anything that would accommodate that. 

Would this need to be done with a script and if so, can i use the pill picker and scripting at the same time?

 

Thank you

1 ACCEPTED SOLUTION

Shivalika
Mega Sage

Hello @BrunoAguiar428 

 

I just answered this question 2 mins ago by somebody else. 

 

Use below 👇 script 

 

var html = RICHFIELD.toString();

 

    // Decode HTML entities using GlideStringUtil

    var decoded = GlideStringUtil.unescapeHTML(html);

 

    // Convert <br> to newline (optional), then strip all other tags

    var plainText = decoded.replace(/<br\s*\/?>/gi, '\n')

                           .replace(/<[^>]*>/g, '');

 

This works perfectly. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

View solution in original post

14 REPLIES 14

Shivalika
Mega Sage

Hello @BrunoAguiar428 

 

I just answered this question 2 mins ago by somebody else. 

 

Use below 👇 script 

 

var html = RICHFIELD.toString();

 

    // Decode HTML entities using GlideStringUtil

    var decoded = GlideStringUtil.unescapeHTML(html);

 

    // Convert <br> to newline (optional), then strip all other tags

    var plainText = decoded.replace(/<br\s*\/?>/gi, '\n')

                           .replace(/<[^>]*>/g, '');

 

This works perfectly. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

BrunoAguiar428
Tera Expert

@Shivalika Thank you for your quick reply! Do I need to make RICHFIELD the name of the variable or that script is good to go as-is?

Hello @BrunoAguiar428 

 

Yes you need to make rich field the whole variable which you want. Basically the "rich text variable" - if you are merging multiple variables then that, if single then that. 

 

Rest all should be good. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

BrunoAguiar428
Tera Expert

@Shivalika Thank you for clarifying , I have 5+ pills that need converting. I will give this a try and report back. Thanks again.