The CreatorCon Call for Content is officially open! Get started here.

Attachment on a form in custom application does not get saved once submit is clicked.

akhilrajt
Mega Contributor

Hello Community folks,

 

I'm experiencing an issue while filling a form in custom application.

 

When a user attaches a file to the custom form and submits it, the attachment is not being saved or associated with the record.

This issue is related to UI Experience.

Attached screenshots shows before submitting the record("test candidate doc.pdf"- attached filename) with attachment.
After clicking submit and open the saved record, the file does not exists.

 

 Seeking support to troubleshoot and fix this issue. Thank you

7 REPLIES 7

kaushal_snow
Mega Sage

Hi @akhilrajt ,

 

I’ve seen this happen before, the file appears before submit, but after submission does not stay with the record. That usually means the attachment is uploading temporarily (or attached to a temp table / wrong record) but not being bound properly when the record is saved.....

 

>>>>> Add an After Insert Business Rule on your custom table.

 

In that script, find any sys_attachment records whose table_sys_id is empty / wrong, but maybe attached under a temporary container / wrong table. Update the sys_attachment records to set table_name = your custom table’s name, and table_sys_id = the new record’s sys_id. Optionally, use GlideSysAttachment.copy() if the attachment has to be copied rather than moved....

 

(function executeRule(current, previous /* null on insert */) {
// only for newly created records
if (previous) return;

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'temp_table_name_or_incorrect_table');
// maybe use some way to identify which attachments belong (filename or user, maybe sys_updated_on)
gr.addQuery('table_sys_id', '');
gr.query();
while (gr.next()) {
gr.table_name = current.getTableName();
gr.table_sys_id = current.sys_id;
gr.update();
// Or use GlideSysAttachment or other api depending on context
}
})(current, previous);

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

hi @kaushal_snow ,

 

Thank you for your response.

 

We have resolved the issue. We discovered that by changing the UI Type of the client script from All back to Desktop, the attachments are now saving as expected.

 

Regards,

Akhil Raj TM

@akhilrajt 

what was that client script doing and how was it interrupting with the attachment not getting saved?

please share the exact root cause and the solution so that it helps future members.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@kaushal_snow 

I don't think this will work.

Can you try this at your end and see if that works and share your findings?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader