Generate PDF through UI Action and email notification?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2023 05:02 AM
Dear Community,
I have a requirement where I want to generate pdf through UI Action and once we click on the UI Action it will trigger one notification where the pdf will be send as an attachment.
for that I have create below things:
UI Action
----
Name - Generate PDF
Table - L1(custom table)
script:
gs.eventQueue('x_infte_intellectu.ia_certificate', current, '', '');
gs.addInfoMessage('Certificate sent');
action.setReturnURL(current);
var ia = new GlideRecord('x_infte_intellectu_ia');
ia.addQuery('sys_id', current.select_intellectual_asset);
ia.query();
if (ia.next()) {
if (ia.status == '17') {
ia.status = '30';
ia.update();
}
}
var htmlText = "create pdf";
var targetTable = "x_infte_intellectu_iav";
gs.addInfoMessage("target table"+targetTable);
var targettableSysid = "90a2e1c31bf825100e1ba935624bcb37";
var pdfName = "pdfgenerated";
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
gs.addInfoMessage("result"+ v);
var result = v.convertToPDF(htmlText, targetTable, targettableSysid, pdfName);
gs.addInfoMessage("result"+ result);
gs.info("PDF result :" + JSON.stringify(result));
var attachment = new GlideRecord("sys_attachment");
attachment.get(result.attachment_id); // replce sys_id of attchemnet your attachment id
var attcontent = new GlideSysAttachment().getContentStream(attachment.sys_id);
new GlideSysAttachment().writeContentStream(current, attachment.getValue("file_name"), attachment.getValue('content_type'), attcontent);
Getting below infomessage
Message
PDF result :{"message":" Given target record [x_infte_intellectu_iav - 90a2e1c31bf825100e1ba935624bcb37] does not exist.","request_id":"68235559c3e4711029f2728dc0013145","status":"failure"}
​
please guide me how do I accomplish the requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2023 10:09 PM
Hello,
In which table attachment is getting stored and for which table notification configured?
Please check "Include Attachment" is checked or not in Notification.
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2023 10:16 PM
Hi Siva,
The attahment we have to generate from the notification - currently a Certificate like formate we are generating using email layout and template but it is getting displayed in the body when notification is sent.
Notification is being created on the same table where I have created the UI Action (custom table ).
I believe include attachment checkbox is something which will send all the attachments from triggering record as an attachment to email.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2023 10:23 PM
if you add file to the record on which notification is present and you check the checkbox of Include attachment then file will automatically go in the email
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2023 10:26 PM
Hi Ankur, Thanks for your response , that's actually not a file which we want to send rather it's a specific format of certificate created using email layout and email template where we are populating some data from other tables and created a certificate.That we are send as an attachment in an email.
however the Include attachment is checked on Noti level.