- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2024 05:21 AM
Hi,
I have a table where i want to copy the attachment to Security incident from Security request.
In Security request we have a UI action called " convert to security incident" once it is converted Security incident will be created and the attachment to be copied over.
I tried using After -insert BR. but its not working . ANywhere im goin wrong? can anyone suggest on this
Here is the code which i tried
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2024 08:43 AM - edited 11-25-2024 08:44 AM
Hello @NAIDILE S ,
Please try This After insert Business Rule:
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Pooja.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2024 05:45 AM - edited 11-25-2024 06:09 AM
Since your Business Rule is running on the sn_si_incident table, 'current.sys_id' will be the sys_id of the incident record, so it is correct to use it as the 4th parameter in the copy method. The second parameter needs to be the sys_id of the request record. Luckily, when the UI Action is used, the parent field on the incident is populated with a reference to the request, so you can use
attachment.copy(sourceTable, current.parent, targetTable, current.sys_id);
I wouldn't recommend altering the out of box UI Action as you will miss out on any updates that are made to the script or condition in future releases. You especially don't want to add code that creates another incident when the out of box script already does that nicely, linking the two records, assigning the incident, and displaying an ifo message with the link to the new incident.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2024 05:56 AM
Hello @NAIDILE S
- There is no need to create separate BR as this will run even when new record is inserted without click of UI button.
- Try to copy the attachment when record is created.
Please refer to the script below:
// Ensure this script is added to the "Convert to Security Incident" UI Action
// Create the Security Incident record
var incidentGr = new GlideRecord("sn_si_incident");
incidentGr.initialize();
incidentGr.short_description = current.short_description; // Copy fields as needed
incidentGr.description = current.description;
incidentGr.some_field = current.some_field; // Copy other fields if needed
incidentGr.insert(); // Insert the new Security Incident record
// Copy attachments from the Security Request to the new Security Incident
var attachment = new GlideSysAttachment();
try {
attachment.copy("sn_si_request", current.sys_id, "sn_si_incident", incidentGr.sys_id);
gs.addInfoMessage("Attachments copied successfully to the new Security Incident.");
} catch (e) {
gs.addErrorMessage("Error copying attachments: " + e.message);
}
// Redirect to the new Security Incident (optional)
action.setRedirectURL(incidentGr);
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2024 08:50 PM
Thanks for the solution, using BR it worked for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2024 08:43 AM - edited 11-25-2024 08:44 AM
Hello @NAIDILE S ,
Please try This After insert Business Rule:
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Pooja.