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
09-27-2024 07:02 AM
Hi @VG3 ,
@-O- is correct, there already is an attachment button or functionality built in to save attachments in the workspace form. Again as @-O- stated it's found in the side panel still identified by the paperclip icon.
Is your intention to save to the record you're looking at or to some other table? If some other table, then build that functionality within the UI page itself.
Here is a very not so great example:
From HR workspace the agent might have to attach an attachment on an incident. ( I told you it was not so great of an example)
Create the UI Action that opens the UI Page ( think you have this part)
The UI Page with simplest example
HTML markup
<button type="button" class="btn" onclick="saveAttachment('${RP.getParameters().sysparm_table}', '${RP.getParameters().sysparm_sys_id}')">Attach</button>
Result:
A couple of things to note:
1) RP won't work in a scoped UI page so you'll need to use location or something to pull the passed values
2) The Save button can be removed and just straight call the saveAttachment('table', 'sys_id') in the client script for better user experience.
Of course, this was just a proof of concept, so please test and refactor as needed. And always try and use first what is available in the platform.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2024 10:50 AM
Thanks @ChrisBurks and @-O- ,
My main intention is to upload the excel data to created tasks via workspace UI action click....
Any oob workspace actions like that ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2024 12:14 PM
Hi @ChrisBurks ,
I have one question,
How did you use/call the saveAttachment() client script in UI Page in your HR case UI action example ? Sample script please ?
As per your previous comment saveAttachment() not supported in workspace.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2024 01:44 PM
Thanks @ChrisBurks , saveAttachment() worked in workspace as well , I tried based on your suggestion...
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2024 05:34 PM - edited 09-30-2024 12:15 AM
@VG3 I jusr realized you are not the O.P, sorry for that 🙂