Script Catalog Items Description to Request without HTML formating

jacobpeterson
Mega Expert

Hello,

I'm trying to include the description from a Catalog Item to a Request's Descriptions. The issue is that it's including the HTML

I'm using this to do it:

if (current.order_guide != ''){
var request = new GlideRecord('sc_request');
request.get(current.request);

var itemDescription = current.cat_item.description.getDisplayValue();
itemDescription = itemDescription.replace(/<(?:.|\n)*?>/gm, '').replace(/ /g, ' ');

current.description = itemDescription;

The code is working to remove all the <p></p>'s and </li><li>'s. I got line 5 from another forum and I'm not sure exactly how to read it. My issue is that I need all the </li> to create a new line of text. Does anyone know how to tweak line 5 to accomplish this?

1 ACCEPTED SOLUTION

jacobpeterson
Mega Expert

If anyone has a better approach please share but I ended up calling out the HTML tags individually using this list:



itemDescription = itemDescription.replace(/<li>/g, '').replace(/\//g, '').replace(/<p>/g, '').replace(/<ul>/g, '').replace(/<li>/g, '\n').replace(/&#34;/g, '"');



Please note that I remove the initial <li> items and then the /'s by using /\//g and then replace the leftover <li> with \n's. Also, the &#34; had to be replace with " for inches.


View solution in original post

1 REPLY 1

jacobpeterson
Mega Expert

If anyone has a better approach please share but I ended up calling out the HTML tags individually using this list:



itemDescription = itemDescription.replace(/<li>/g, '').replace(/\//g, '').replace(/<p>/g, '').replace(/<ul>/g, '').replace(/<li>/g, '\n').replace(/&#34;/g, '"');



Please note that I remove the initial <li> items and then the /'s by using /\//g and then replace the leftover <li> with \n's. Also, the &#34; had to be replace with " for inches.