- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 09:05 AM
Greetings, people.
The business analyst of an app that I'm developing asked me to find out whether it's possible to make ServiceNow automatically add attachments (which contain a lot of important info related to the records) to new records generated from templates. I tried adding the attachments to the templates themselves, but the templates were triggered, they would not add any attachments to the newly-generated records. Then my project manager suggested adding links to the Knowledge Base, but the business analyst vetoed that option. So now I have to return to the old track.
Does anyone have any idea how I can achieve this? Any help would be greatly appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 09:51 AM - edited 10-18-2022 09:56 AM
Do you want these attachment to only be added if they used the template? For example, let's say that someone creates one of these records manually but they created a record and manually populated all of the same fields and values that the template would have applied, should those also have the attachments added?
An approach that should work regardless of the answer to that question would to add a reference field to the table:
Label: Template
Name: u_template
Reference: sys_template
You would want each Template to populate the Template field with a reference to itself. Then, you could simply add the attachments to the template use a business rule to copy them from the template to the record.
I don't know of anything out of box that indicates if the record was created by a template, and if so which template. I also do not know of any client or server side triggers or events that would be emitted when using a template to create a record.
Business rule example:
Runs: After and only on insert with a condition that the template field is not empty.
var attachment = new GlideSysAttachment();
attachment.copy('sys_template', current.getValue('u_template'), current.getTableName(), current.getUniqueValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 09:51 AM - edited 10-18-2022 09:56 AM
Do you want these attachment to only be added if they used the template? For example, let's say that someone creates one of these records manually but they created a record and manually populated all of the same fields and values that the template would have applied, should those also have the attachments added?
An approach that should work regardless of the answer to that question would to add a reference field to the table:
Label: Template
Name: u_template
Reference: sys_template
You would want each Template to populate the Template field with a reference to itself. Then, you could simply add the attachments to the template use a business rule to copy them from the template to the record.
I don't know of anything out of box that indicates if the record was created by a template, and if so which template. I also do not know of any client or server side triggers or events that would be emitted when using a template to create a record.
Business rule example:
Runs: After and only on insert with a condition that the template field is not empty.
var attachment = new GlideSysAttachment();
attachment.copy('sys_template', current.getValue('u_template'), current.getTableName(), current.getUniqueValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 11:56 AM
Thank you for your response! I'll ask my colleague (who has more access than I do) to give this a try.