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

Hello @BrunoAguiar428 

 

First, @BrunoAguiar428  - is this returning you result - 

fd_data._1__get_catalog_variables.pill_1

 

I mean where have you declared pill1?

 

I don't think this is correct, can you tell me your requirement? I will tell the script. But please mark both my answers as solutions, HTML one and this also - once they work. 

 

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 That is a pill that gets filled out with the form. I know when I use the pill picker it works and populates into description..

 

I have a total of 7 variables/pills on the form . Not all of them get filled out , but in this case that particular pill/variable is populated when filling out the form. I must not be bringing it in correctly.

Hello @BrunoAguiar428 

 

Instead of using pill1 and pill2 - directly using the variable names. 

 

And you want to concatenate all the variables values and then remove the HTMl tags right ? 

 

Then you need to just use "+" to concatenate it with a space string. 

 

Then the removing HTML tags thing will work 

 

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 I figured out how to get the variables in. I needed to do:

var request_new_requirements = fd_data._1__get_catalog_variables.request_new_requirements;

 

But I kept getting this error when using your script: "Error: Java class "com.glide.util.StringUtil" has no public instance field or method named "unescapeHTML".

 

I ended up getting it working by using the following:

decoding = decoding.replace(/<br\s*\/?>/gi, '\n').replace(/<[^>]*>/g, '');
desc += "\n" + decoding;

Hello @BrunoAguiar428 

 

Yes that StringUtil might not exactly work in the flow designer script part. 

 

However the string functions and pattern like replace and regex used is working as you already saw. 

 

Kindly mark my original answer as helpful and accept solution. 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