- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 11:10 PM
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> </p>
<p> </p>
<p> </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.
(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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 11:26 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 11:26 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 11:28 PM
@Hrishabh Kumar You need to regular expression here. Try below code
(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 regExp = /\[Recipient's Name\]/;
var newHtml = html.replace(regExp , "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);
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 11:42 PM
@SANDEEP28 , tried but it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 12:40 AM - edited 07-27-2023 12:41 AM
@Hrishabh Kumar It should work. I stored your html content in description field of one incident and updated using below script & it worked.
With Regular expression, you can match any text.
var grIncident = new GlideRecord('incident');
if (grIncident.get('a83820b58f723300e7e16c7827bdeed2'))
{
var html = grIncident.description
var regExp = /\[Recipient's Name\]/;
var newHtml = html.replace(regExp , "Sachin Tendulker");
gs.info(newHtml);
}