How to Delete an Uploaded Attachment from UI Builder Workspace After Successful Submission?

girishbs06
Tera Expert

Hi Community,

I am developing a Bulk Asset Upload functionality in a custom ServiceNow Workspace using UI Builder.

Current Implementation

The workflow is as follows:

A manager uploads an Excel (.xlsx) file using the Attachments component.

The attachment is associated with an existing u_asset_update_request parent record.

A server-side validation process reads the Excel file and validates each Asset Tag against the alm_hardware table.

UI Builder displays:

Valid records

Invalid records

No-change records

Preview of current versus proposed values

When the manager clicks Submit for Approval, separate u_asset_update_request records are created for every valid asset with changes.

All created request records share the same Batch ID.

Current Issue

After successful submission, I want to automatically delete the uploaded Excel attachment so that the Attachments component becomes empty and the manager can upload a new file.

Expected behavior:

The uploaded Excel attachment should be deleted only after successful submission.

The Attachments component should show no attachments available.

The component should allow the manager to upload another Excel file.

What I Have Tried

I tested attachment deletion through Scripts - Background using the following code:

var attachmentSysId = 'ATTACHMENT_SYS_ID';

 

var attachment = new GlideSysAttachment();

attachment.deleteAttachment(attachmentSysId);

 

var verify = new GlideRecord('sys_attachment');

 

if (verify.get(attachmentSysId)) {

    gs.print('FAILED: Attachment still exists');

} else {

    gs.print('SUCCESS: Attachment deleted');

}

This works successfully from the background script, and the attachment is deleted from the sys_attachment table.

 

 

However, I am unable to achieve the same behavior dynamically from UI Builder Workspace after the Submit for Approval action.

0 REPLIES 0