- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Copy Attachments Child to Parent Security Incident and vice versa to ensure synced attachments
Dear ServiceNow Community Colleagues,
Please can I request help/guidance with the following use case requirement:
What is the best configuration I can use to ensure Attachments are copied from Child Security Incident to Parent Security Incident and vice versa? (Table: 'sn_si_incident')
I basically need to ensure all related 'Attachments' are always in sync, for related records, so that whether you view the attachments on the child or related/linked parent Security Incident, all related attachments will be visible and in sync on both the child and parent record.
Is this possible via the combination of a scripted Business Rule and Flow/Subflow for example?
I would appreciate any advice/guidance/working example of how best to achieve this configuration.
Many Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
try this
(function refineQuery(current, parent) {
var tableName = parent.getTableName();
var queryString = "table_name=" + tableName + "^table_sys_id=" + parent.getValue("sys_id"); //default query
switch (tableName) {
case "sn_si_incident":
queryString = "table_nameINsn_si_incident" + "^table_sys_idIN" + parent.getValue("sys_id");
//find the related New Security Incident
queryString += u_getRelatedRecords("sn_si_incident", "parent_security_incident", parent.getValue("sys_id"));
break;
}
current.addEncodedQuery(queryString);
function u_getRelatedRecords(table, field, sysId) {
var result = "";
var gr = new GlideRecord(table);
gr.addQuery(field, sysId);
gr.query();
while (gr.next()) {
result += "," + gr.getValue("sys_id");
}
return result;
}
})(current, parent);
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
4 weeks ago
@Ankur Bawiskar You are brilliant, we are very lucky to have you, kind sir! This works perfectly and is definitely the best solution rather than copying attachments! Thank you so much as always for the time you took to help me, this will certainly help others also, many thanks Ankur 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @Ankur Bawiskar just a question, if it is at all possible even?
Is there a way to amend/add to this above Query script, so that one can see all the 'Related Attachments', when one is in the Child Security Incident, so I mean, when you are within the Child Security Incident, you can also see the attachments related to the Parent.
With this existing Query script (as above), you can see all Related Attachments (for Parent + Child), when you are on the Parent Record, but when you are in the Child Security Incident, you cannot see the Related Attachments for the Parent displayed also.
Is it straight forward to update/amend this script, so that it works whether you are on Parent or Child record, to show ALL Related Attachments?
Many thanks kind sir if you have the time to answer my query 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you will have to tweak that I believe.
OR
You might have to create separate related list for that.
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
