How to get the attachments from the parent case table to the case task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2023 08:27 AM
Hello Everyone,
I have a case table where we can add the attachments and also in the related list of case table I have case task, when I open that I want to add the attachments from the case task so that I can get the attachments which are there in the parent case table. This I should get by clicking on the button which is UI action.
Can anyone help me in achieving this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2023 09:06 AM
Yes, I can help you with that. Here are the steps to achieve this in ServiceNow:
- Create a UI Action:
Go to the Case Task table in ServiceNow and create a new UI action. Set the following values:
- Name: Add Attachment
- Table: Task
- Action name: add_attachment
- Define the UI Action Script:
Next, add the following code to the UI Action script:
(function() {
var ga = new GlideAjax('AttachmentUploader');
ga.addParam('sysparm_name', 'addAttachment');
ga.addParam('sysparm_table_name', 'task');
ga.addParam('sysparm_table_sys_id', g_form.getUniqueValue());
ga.addParam('sysparm_sys_id', g_form.getUniqueValue());
ga.addParam('sysparm_target', 'case');
ga.addParam('sysparm_target_sys_id', g_form.getValue('parent'));
ga.addParam('sysparm_nostack', 'yes');
ga.addParam('sysparm_value', 'test');
ga.getXML();
})();
- Save the UI Action:
Save the UI Action after adding the script.
- Test the UI Action:
Test the UI action by navigating to a Case Task record and clicking on the "Add Attachment" button. The attachment should now be added to the parent Case record's attachments list.
That's it! You have now successfully added a UI action to add attachments from a Case Task record to the parent Case record in ServiceNow.
Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2023 10:24 AM
Hello Syed,
Thanks for the quick response.
I didn't find AttachmentUploader in OOB script include, can you please help me with that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2023 10:43 AM
The AttachmentUploader script include is not an out-of-the-box script include in ServiceNow. Instead, it is a custom script include that needs to be created in your ServiceNow instance.
Here are the steps to create the AttachmentUploader script include:
Navigate to System Definition > Script Includes in the left navigation pane.
Click the New button to create a new script include.
Set the following values for the new script include:
- Name: AttachmentUploader
- Application: Global
- Accessible from: All application scopes
Add the following code to the script include:
var AttachmentUploader = Class.create();
AttachmentUploader.prototype = {
initialize: function() {
},
addAttachment: function(table_name, table_sys_id, sys_id, target, target_sys_id, value) {
var dialogClass = GlideModal ? GlideModal : GlideDialogWindow;
var attachmentDialog = new dialogClass('attachment_select', false, 600);
attachmentDialog.setTitle('Add Attachment');
var view = attachmentDialog.getView('sys_attachment', 'select_file');
view.setAttribute('table_name', table_name);
view.setAttribute('table_sys_id', table_sys_id);
view.setAttribute('sys_id', sys_id);
view.setAttribute('target', target);
view.setAttribute('target_sys_id', target_sys_id);
view.setAttribute('value', value);
attachmentDialog.render();
},
type: 'AttachmentUploader'
Save the script include.
Once you have created the AttachmentUploader script include, you can use the UI action script that I provided earlier to add attachments from a Case Task to the parent Case record in ServiceNow.
Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!
};