- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 09:20 PM
Hi All,
I have a requirement to auto attach one document to each record of the table once it is created. Please provide a solution to how to do this and what all needs to be done for this.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 10:44 PM
then do this
1) create system property of type string and attach your file to that system property
2) Use before/after insert BR on that table and use this script
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sys_properties");
gr.addQuery("name", "static_file"); // name of property in query
gr.query();
if (gr.next()) {
new GlideSysAttachment().copy('sys_properties',gr.getUniqueValue() , current.sys_class_name, current.getUniqueValue());
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 09:47 PM
File I haven't saved anywhere yet and script also yet to write. Where can I save my attachment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 10:44 PM
then do this
1) create system property of type string and attach your file to that system property
2) Use before/after insert BR on that table and use this script
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sys_properties");
gr.addQuery("name", "static_file"); // name of property in query
gr.query();
if (gr.next()) {
new GlideSysAttachment().copy('sys_properties',gr.getUniqueValue() , current.sys_class_name, current.getUniqueValue());
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 11:44 PM
Hi @Ankur Bawiskar ,
I tried this thing but it is not working attachment is getting attached . Can you please tell what could be the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 11:46 PM
share your configuration and script you are using
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 11:52 PM
Hi @Ankur Bawiskar ,
Please find attached screenshots which I have configured.