How can i save a file like attachment in UI Page?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 12:32 PM
How can i save a variable file type like attachment, i have my code
HTML
<input id="attachment" name="attachment" mandatory="true" type="file"/>
<g:dialog_buttons_ok_cancel ok_text="Actualizar" cancel_text="Cancelar" ok="updateCom();return true" cancel="closeWindow();"/>
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();
}
Processing script
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);
}
this code works, but the problem is that the variable 'attachment' just gave me the title of the original document(for example: documentTest.xlsx), I need the excel the i have in the file variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 10:50 PM
Hello @EvilRojo
Update your processing script :-
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', 'YOUR_TABLE_NAME');
attachmentGR.addQuery('table_sys_id', 'YOUR_RECORD_SYS_ID');
attachmentGR.query();
if (attachmentGR.next()) {
var newFileName = 'CustomFileName'; // Replace 'CustomFileName' with your desired custom file name
// Set the new file name for the attachment
attachmentGR.file_name = newFileName;
attachmentGR.update();
}
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 09:38 AM
It not works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 05:52 PM
Hi @EvilRojo,
Quick question: From your example code you posted it looks like the UI Page is being called by a UI Action. Is that correct?
As @-O- suggested there is already an out-of-box way to add attachments and you don't have to even create a UI page. From a UI Action or even a Client Script you can call "saveAttachment(<table name>, <sys_id>)" and it will inherently bring up the things necessary to add an attachment.
Here are some examples.
As client script on an onchange
Working example:
UI Action
Working example for UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 10:47 AM - edited 09-26-2024 11:17 AM
Hello @ChrisBurks ,
save attachment(table name, Sysid) not working in workspace UI builder like I have used UI Page like below,
Html code --- on click() Handel attachment function
Client script :
I used save attachment () but window is not opening
And in workspace UI builder glideDialoWindow.get() will work or not ?
Please check and correct me if I am wrong
Thanks in advance!