.replace() function not working properly.

Hrishabh Kumar
Giga Guru

I am trying to update an HTLM by using .replace() function, which is working for certain text and not working for certain text.

 

I have shared the code and html below.

 

HTML:

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.certificate {
border: 2px solid #000;
padding: 20px;
max-width: 600px;
margin: 0 auto;
}
.certificate-title {
text-align: center;
font-size: 24px;
margin-bottom: 20px;
}
.certificate-content {
text-align: center;
font-size: 18px;
}
.certificate-name {
font-size: 24px;
font-weight: bold;
margin-bottom: 10px;
}
.certificate-date {
font-size: 18px;
}
</style>
<div class="certificate">
<div class="certificate-title">Certificate of Achievement</div>
<div class="certificate-content">This certificate is awarded to:
<div class="certificate-name">[Recipient's Name]</div>
for their outstanding performance in [Course/Event Name].
<div class="certificate-date">Date: [Date]</div>
</div>
</div>

 

Business Rule :

commented line 3 ie..var newHtml = html.replace("Certificate of Achievement", "Sachin Tendulker"); is working properly and html is getting updated, and I can see the changed on the generated PDF.

But same function is not working for line 4
ie.. var newHtml = html.replace("[Recipient's Name]""Sachin Tendulker");
 
I need to update "[Recipient's Name]" text in HTML and it is not getting updated.

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	gs.addInfoMessage('certificate will be provided soon 7');
	var html = current.u_certificate;
	// var newHtml = html.replace("Certificate of Achievement", "Sachin Tendulker");
	var newHtml = html.replace("[Recipient's Name]", "Sachin Tendulker");
	var table = 'sys_user';
	var user_sys = current.getValue('u_user');
	var filename = 'Ecertificate'+current.u_user.name;

	var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
	var result = v.convertToPDF(newHtml, table, user_sys, filename);

})(current, previous);

 

1 ACCEPTED SOLUTION

Prince Arora
Tera Sage
Tera Sage

@Hrishabh Kumar 

 

I think it is getting confused with "Recipient's Name"

 

Can you update it as "Recipients Name" and try below code

 

var newHtml = html.replace("[Recipients Name]", "Sachin Tendulker");

 

 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

View solution in original post

5 REPLIES 5

Yes,

but the the generated PDF does not contain the changed htlm.

 

But thanks for the information.