Need to generate a PDF in ServiceNow without attaching it to any record, for use in email.

Astik Thombare
Tera Sage

Hi Community,

 

I'm generating a PDF file in ServiceNow that I intend to use for sending an email. I don’t want this file to be attached to any record, as I plan to retrieve it using the file name. However, the GlideSysAttachment API requires a table name and a record sys_id to create the attachment.

 

I’m aware that we can use a "before insert" Business Rule to attach the file to the sys_email record, but since the PDF contains a large number of records, I’m concerned this may impact performance.

 

Is there any way to create or temporarily store the file without linking it to a specific record?

 

Thanks in advance!

2 REPLIES 2

Muhammad Salar
Giga Sage

Hello, The only way i can think of is that you can attach it to record, download it and then delete it immediately in same code. 
I have done it with ui action like this

if (typeof window == 'undefined') {
   remove();
}

function pdf() {
    var sysId = g_form.getUniqueValue().toString();

    var kbGa = new GlideAjax('downloadDocument');
    kbGa.addParam('sysparm_name', 'getContentForPdf');
    kbGa.addParam('sys_id', sysId);
    kbGa.getXML(getRequired);

    function getRequired(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var json = JSON.parse(answer);
   
        for (var i = 0; i < json.length; i++) {
            top.window.open('/sys_attachment.do?sys_id=' + json[i].id);
            gsftSubmit(null, g_form.getFormElement(), 'action_name');
        }
    }

}

function remove() {
    var rem = new downloadDocument();
    rem.removeAtt(current.sys_id);
    gs.addInfoMessage('deleted');
    action.setRedirectURL(current);  
}

Muhammad Salar
Giga Sage

Hello, did you try this approach?