Convert HTML Type Field Value to String With Formatting Including Bullet Points and Alignment

Sai kumar123
Tera Expert

Hi, is there any way to convert HTML type Field Values to a String, without loosing the Sentence alignment, bullet points inserted and convert it to string as it is.

There is a requirement where, i need to get the value of HTML field types and display them in PDF, So in that PDF i am getting multiple bullet points and not a desired format peresent in that value.

So If any one knows how to convert it to a string Value as it is, Please Let Me Know

9 REPLIES 9

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Sai kumar123 

As per my knowledge, it’s not possible—you would lose the structure since the string is unformatted, whereas HTML contains formatting and tags.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Robert H
Mega Sage

Hello @Sai kumar123 ,

 

No need to convert the HTML value. The PDF generation API can directly work with the HTML value. Here is a basic example:

 

Here I'm having a Demand record with a Business case in HTML:

RobertH_0-1744697170844.png

 

Here is how to convert that HTML into a PDF and attach it to the Demand:

var pdfUtil = new sn_pdfgeneratorutils.PDFGenerationAPI;

var gr = new GlideRecord('dmn_demand');
var html;
if (gr.get('number', 'DMND0001102')) {
    html = gr.getValue('business_case');
}

var tableToAttach = 'dmn_demand',
    sysIdToAttach = gr.getUniqueValue(),
    pdfFileName = 'Business case for Demand';
pdfUtil.convertToPDF(html, tableToAttach, sysIdToAttach, pdfFileName);

 

This is the PDF that will be created:

RobertH_1-1744697279931.png

 

Regards,

Robert

 

Hi Robert, thanks for your input, I had already implemented the usage of PDFGenerationUtils API, but some how when i am getting that value in backend, i mean i wrote a SI where i am using this PDF API , I am getting multiple bullet points , even though there is one Bullet point in HTML Field, I dont know why this is happening

anyway i try to see where it went wrong

Hello @Sai kumar123 ,

 

Thanks for the update. If you'd like to post that Script Include code here I can check why you are getting unexpected results.

 

Regards,

Robert