How do you remove HTML <p> formatting from form field?

MBarrott
Mega Sage

I have a description field on demand task form. Users can input a description from the Create a Demand catalog item.

 

The issue I'm seeing is that the data they provide is coming in within <p></p> HTML on either end (see screenshot)

 

Is there a simple solution to remove these tags?

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage
Giga Sage

Hi @MBarrott ,

 

Could you please refer the below article ,

write after insert BR with reference of below article
https://www.servicenow.com/community/developer-forum/script-catalog-items-description-to-request-wit... 

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

View solution in original post

7 REPLIES 7

swathisarang98
Giga Sage
Giga Sage

Hi @MBarrott ,

 

Could you please refer the below article ,

write after insert BR with reference of below article
https://www.servicenow.com/community/developer-forum/script-catalog-items-description-to-request-wit... 

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

Hi @swathisarang98,

 

This solution worked perfectly as an insert-BR, thank you!

AshishKM
Kilo Patron
Kilo Patron

Hi @MBarrott , 

Are you using record producer for demand creation then you can use the below code line in script section, this will remove any HTML tag from incoming description data.

 

current.description = producer.description.replace(/<[^>]*>/g, ' ');

 

You can test this code in background script

 

var description = '<p>test description</p>';
description = description.replace(/<[^>]*>/g, ' ');
gs.info("Description->"+description);

 

-Thanks,

AshishKM

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Thank you very much . I didnt know you could append

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

to a variable to strip the formatting like that. That will be very useful 🙂

Andy