Unable to attach the attachments from record producer to target table

shaik_irfan
Tera Guru

HI,

 

I am using a variable type attachment and  user attach the documents and submit an incident. I have a script written on the record producer but seems it is not working. Can anyone please help me what wrong i am doing

 

	var attachment = new GlideSysAttachment();
	var incID = current.getUniqueValue();
	var sysAttachGR = new GlideRecord('sys_attachment');
	sysAttachGR.get("table_sys_id",incID);

	var copiedAttachments = attachment.copy('sys_attachment', sysAttachGR.sys_id, current.getTableName(), current.sys_id);
	
	
1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,

Please follow the steps below to achieve your requirement:

1) Couple of things to note here, when you add an Attachment in your custom variable of Type = Attachment, ServiceNow will not show them in the header of the record which you are expecting to be visible in the Attachment header on the Incident form.

Reason why: When ever you upload an Attachment using the Attachment Type variable all the files which gets uploaded in the Attachment table has a Table Name starting with "ZZ_Table Name".

For example :"ZZ_YYincident". Refer to screenshot below:

find_real_file.png

Now as per ServiceNow design below is the principle why it will not be shown:

"

ServiceNow automatically hides that attachment so that it only displays the contents in the form and doesn’t look like an image attached to the record. To do this, you have to:

  1. Go to the sys_attachment table
  2. Rename the "Table Name", appending the string "ZZ_YY" to the table name.

This is a convention that service-now uses to hide the attachment icon from the record for that image."

Refer to the HI Article below which confirms this:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0868420

Also one point to note here is you do not need a script at all for this scenario, as by default when ever you upload an Attachment, by default that gets visible in Activity Section of the record as shown below and user can access from there:

Refer to multiple screenshot with different file type:

find_real_file.png

find_real_file.png

 

This should resolve your query. Let me know if you have a follow up question on this.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

14 REPLIES 14

Saurav11
Kilo Patron
Kilo Patron

Hello

Please find below articles you may find helpful

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0696061

Please mark answer correct/helpful based on impact

@Saurav 

 

I did gone through this article but i did not understand the resolution

 

So to resolve the issue, please remove the line in the script section of the record producer.

 

 

It is taking about current.intialize.do yu have it anywhere in the script?

JagjeetSingh
Kilo Sage
Kilo Sage

Check sys_attachment table after submitting the record.

You'll see that attachment is created in table but with prefix ZZ_YY in table name.

This is why you don't see these attachments attached to records but you can see these in activity stream. Add "attachments" in activity stream and see if you can see the attachments.

If yes, then you can do something to remove the prefix OR you can copy the attachments using GlideSysAttachment.copy();

Here is an article about it.

 

Jagjeet Singh
ServiceNow Community Rising Star 2022/2023