want to store file in sys_attachment table through custom UI page.

rohit_ranjan
Tera Contributor
 fileUpload: function() {
        gs.addInfoMessage("from Script include");
        var file = this.getParameter('sysparm_file');
        gs.addInfoMessage(" file.name: " + file.name );

        // var attachment = new GlideSysAttachment().write(file, 'sys_attachment', 'Uploaded Excel File', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

        // // Read Excel data
        // var parser = new GlideExcelParser();
        // var excelData = parser.parseExcel(attachment);
        // gs.addInfoMessage(" file: " + file+"excelData: "+excelData);

        return "done";
    },

here, for "gs.addInfoMessage(" file.name: " + file.name )"  I'm getting  undefined, why?
1 REPLY 1

AnimeshP_96
Tera Guru

@rohit_ranjan 
Try this  

var attachmentSysid = '';
var gr = new GlideRecord('my_table');
gr.addEncodedQuery('query');
gr.query();
if (gr.next()) {
var grAttachment = new GlideSysAttachment();
attachmentSysid = grAttachment.write(gr, fileName, 'application/xlsx', attachment);
}

 

client script 

function updateCom() {
gel('table_sys_id').value = 'sys_id_text';
gel('fileName').value = 'NameofDocument.xlsx';
GlideDialogWindow.get().destroy();
}
function closeWindow() {
GlideDialogWindow.get().destroy();
}

 

 

Also ,
have a look into this link , maybe this will help you..

https://deepakvednegi.medium.com/attachment-transfer-moving-files-from-html-input-to-servicenow-reco...


if this resolves your query mark this thread as close , so that others find it easy.!!


Please accept the solution /mark this response as correct or helpful if it assisted you with your question.




Regards,
Animesh