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

i will give this a shot and see what happens

shloke04
Kilo Patron

Hi,

If your query is resolved, please mark the answer as correct and close this thread for others.


Regards,

Shloke

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

Regards,
Shloke

Ankur Bawiskar
Tera Patron
Tera Patron

@shaik.irfan 

I had shared working solution for this 1 year ago

enhance for your requirement

Disable ZZ_YY prefix from attachment when added through record producer

Regards
Ankur

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

Hi @Ankur Bawiskar,

I have written Async insert BR to achieve the same, please guide me why it's not working for me.

 

(function executeRule(current, previous /*null when async*/ ) {

// Add your code here "ZZ_YY"
var gr = new GlideRecord("sys_attachment");
gr.addQuery("x_infte_intellectu_brandname_clearance", "ZZ_YY" + current.getTableName());
gr.addQuery("ca954dd0c3f83d102f7798bc7a013179", current.sys_id);
gr.query();
if (gr.next()) {
gr.table_name = current.getTableName();
gr.update();
new global.VariableUtil().copy(gr.sys_id, current.getTableName(), current.sys_id);
}
})(current, previous);

 

Thank you in advance,

Amol

@Amol Pawar 

can you post a new question and tag me there as this is an older post?

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