Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI action not working in workspace

pk2184046
Tera Expert

Hi all,

    function downloadPDF() {
    var ga = new GlideAjax('sn_hr_core.GSSPDownloadpdf'); // Script Include name
    ga.addParam('sysparm_name', 'generatePDF');
    ga.addParam('sys_id', g_form.getUniqueValue()); // Current record sys_id
    ga.addParam('template_id', 'aa3586312b017a508e43f95fee91bf90'); // Template sys_id
    ga.addParam('pdf_name', 'Online Template.pdf');

    // g_form.showFieldMsg('downloadPDF', 'Generating PDF, please wait...', 'info');

    ga.getXMLAnswer(function(response) {
        if (response) {
                // g_form.save();
            var downloadUrl = '/sys_attachment.do?sys_id=' + response;
            window.location.href = downloadUrl; // Trigger download
                location.reload();
        } else {
            alert('Failed to generate PDF.');
        }
    });
   
}

I'm using the above code to generate a pdf in the hr task which is working in native UI but in the HR agent workspace it is not working. Workspace form button is checked true
workspace code

 

    function downloa
function onClick(g_form) {
    var ga = new GlideAjax('sn_hr_core.GSSPDownloadpdf'); // Script Include name
    ga.addParam('sysparm_name', 'generatePDF');
    ga.addParam('sys_id', g_form.getUniqueValue()); // Current record sys_id
    ga.addParam('template_id', 'aa3586312b017a508e43f95fee91bf90'); // Template sys_id
    ga.addParam('pdf_name', 'Online Template.pdf');

    // g_form.showFieldMsg('downloadPDF', 'Generating PDF, please wait...', 'info');

    ga.getXMLAnswer(function(response) {
        if (response) {
                // g_form.save();
            var downloadUrl = '/sys_attachment.do?sys_id=' + response;
            window.location.href = downloadUrl; // Trigger download
                location.reload();
        } else {
            alert('Failed to generate PDF.');
        }
    });
   
}
@Ankur Bawiskar can you please help
Pasting the script include
var GSSPDownloadpdf = Class.create();
GSSPDownloadpdf.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    generatePDF: function() {
   var recordId = this.getParameter('sys_id');
        var templateId = this.getParameter('template_id');
        var pdfName = this.getParameter('pdf_name');

        var attachmentSysId = new sn_doc.GenerateDocumentAPI()
            .generateDocumentForTask(recordId, templateId, pdfName);

        return attachmentSysId; // Return the sys_id of the attachment
    },

    type: 'GSSPDownloadpdf'
});



0 REPLIES 0