- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks 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
Glad to know.
You will have to adjust your script as per your requirement, the link will give you an idea on how to do. It has different scripts for different tables.
We are not sure what table structure is there and what field is being used in your instance.
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 - last edited 4 weeks ago
Hi @Ankur Bawiskar I am using the Security Incident table (sn_si_incident) and the Parent field (on the Security Incident Response Form) is called 'parent_security_incident'. Do you know what is the full script I should use in this case, as I am not able to get it to work with what I have tried, just wandering what revised script would work, using sn_si_incident table and Form Field that captures Parent is called 'parent_security_incident'. Many thank as always, if you are able to help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
what did you start with script and where are you stuck?
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 - last edited 4 weeks ago
Hi @Ankur Bawiskar - I have tried amending the Query Script for my use case, but it does not function correctly, it brings back 147k Related Attachments, so every attachment related to the sn_si_incident table, instead of just the attachments related to this one specific Parent security incident, with one associated Child Security Incident - I should only in my example see 4 relevant attachments, so something not correct on my query script (attached and screenshots). Would really appreciate in case you can spot where I have gone wrong, many thanks.
(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,parent_security_incident^table_sys_idIN" + parent.getValue("sys_id");
//find the related New Security Incident
queryString += u_getRelatedRecords("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);My table, for my use case is the Security Incident Response table: 'sn_si_incident' and the Parent field in my client's instance, is named: 'parent_security_incident', as opposed to 'parent'.
- 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
