
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2019 11:48 PM
I am creating a pdf with the library jsPDF and this works and I can preview the pdf in the Service Portal.
I now need to write the pdf into an attachment on a case but I cannot get it to work.
First question, which output datatype from jsPDF ( http://raw.githack.com/MrRio/jsPDF/master/docs/jsPDF.html#output ) should I use ? For view on screen I am using datauristring.
My function to write the attachment is in a global script include and looks like this :
insertAttachment: function (gr, fileName, contentType, content){
var contentArr = content.split(',');
var att = new GlideSysAttachment();
att.writeBase64(gr, fileName, contentType, contentArr[1]);
att.writeBase64(gr, fileName, contentType, gs.base64Decode(contentArr[1]));
att.write(gr, fileName, contentType, contentArr[1]);
att.write(gr, fileName, contentType, gs.base64Decode(contentArr[1]));
},
Neither of the writeBase64 works. No attachment is stored.
The two write do write attachments but they cannot be opened.
Of course I have also tried to not do a split on the content input.
Contenttype is set to: application/pdf
Content: I have tried almost all of the possible types available from jsPDF.
I am stuck 😞
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2019 05:43 AM
Have you tried using the Attachment API client side?
If you have the table name and sys_id of the record you want to attach you should be able to do something like this using "blob" as output:
var config = {
'headers':{
'Content-type':'application/pdf',
'Accept':'application/json'
}
}
$http.post("/api/now/attachment/file?table_name=incident&table_sys_id=9d385017c611228701d22104cc95c371&file_name=myfile.pdf",doc.output("blob"),config);
Note: Replace your respective values in the url for table_name, table_sys_id, and file_name. Also remember to pass $http to the client controller
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 11:15 PM - edited 07-10-2023 11:16 PM
I have also kind a similar requirement,
Requirement: I need to download the UI Page using Jspdf but I don,t know How to import Jspdf in servicenow.
Can You please tell me How do it.
Thanks in Advance