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.

1 REPLY 1

Sanjay191
Kilo Patron

Hi @girishbs06 

could you please refer the fucntionality i recently immepliment for the bulk asset data upload 

  • Created the Data Source and Transform Map to transform the data.

  • Created a Flow Designer flow to handle the bulk data upload process.



 

Sanjay191_0-1793693812850.png

 

Sanjay191_1-1793693864397.png



 

for executing the data source you need to create  schedule data import  for the data source that you had created and  the custom action. in custom action please use the below code for the reference.

Sanjay191_3-1793693908489.png

 

You can also consider using this approach. However, if you prefer to proceed with the approach you are currently implementing, please ensure that you include the deletion logic at the beginning of the process. This will delete the previously successfully processed data load file before processing the new one, preventing duplicate or outdated data from being retained and makesure apply the neccessary check as well.

Note: - This is for the catalog item you can configure for your table and make the changes accordingly.


If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You