- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2022 01:41 PM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2022 02:11 AM
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:
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:
- Go to the sys_attachment table
- 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:
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2022 02:11 AM
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:
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:
- Go to the sys_attachment table
- 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:
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2022 02:13 AM
Also to mention that even if you write a script whether in Record Producer script or a Business Rule still it will not be visible on the form and can only be seen in Activity section.
I have tried this in my PDI instance using both Record producer and Business Rule script. Sample script which I have tried and I got all the logs and all lines got executed correctly still it will not shown when I found the HI article mentioned above that this is the expected behavior.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 01:34 AM
Thank you for the reply. What you said is right it is storing as ZZZ and unable to pick it up from there.
Now coming to the solution unfortunately this is a custom table where i do not have OOTB work notes/Comments fields but i have Custom journal field but i dont see the attachment getting attached.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 03:15 AM
Please write a Async Insert Business Rule on your Custom Table and use the script as below:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
gr.addQuery("table_sys_id", 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);
Refer the screenshot as well for reference below:
What this script will do is get rid of that extra "zzz" from the Table Name in Attachment Table and then try to copy it .
I have tested this in my PDI instance and is working fine.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 04:26 AM
Hi,
If your query is resolved, please mark the answer as correct and close this thread for others.
Regards,
Shloke
Regards,
Shloke