- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 03:38 PM
Hi, I am creating a business rule where I want to copy the attachment from incident table to assigned problem table, and I selected before insert and update business rule.
This is my script..
(function executeRule(current, previous /*null when async*/ ) {
var prb = new GlideRecord('problem');
prb.addQuery('parent', current.getUniqueValue());
prb.query();
if (prb.next()) {
GlideSysAttachment.copy('incident', current.getUniqueValue(), 'problem', prb.current.getUniqueValue());
}
})(current, previous);
I do not what I am doing wrong but this is not working.
Please help.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2024 05:37 AM
'Current' refers to the record and table that the Business Rule is running on. Out of the box, you can relate a problem to an incident using the problem_id field on the incident table. If you are using the parent field on the problem table to identify incidents, then your script is fine to start with, but be sure to add to the Filter Condition Parent changes so that it doesn't copy every time the incident is updated. In this case, the fourth parameter in the copy function of GlideSysAttachment to identify the problem record should just be prb.getUniqueValue()
(function executeRule(current, previous /*null when async*/ ) {
var prb = new GlideRecord('problem');
prb.addQuery('parent', current.getUniqueValue());
prb.query();
if (prb.next()) {
GlideSysAttachment.copy('incident', current.getUniqueValue(), 'problem', prb.getUniqueValue());
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2024 05:37 AM
'Current' refers to the record and table that the Business Rule is running on. Out of the box, you can relate a problem to an incident using the problem_id field on the incident table. If you are using the parent field on the problem table to identify incidents, then your script is fine to start with, but be sure to add to the Filter Condition Parent changes so that it doesn't copy every time the incident is updated. In this case, the fourth parameter in the copy function of GlideSysAttachment to identify the problem record should just be prb.getUniqueValue()
(function executeRule(current, previous /*null when async*/ ) {
var prb = new GlideRecord('problem');
prb.addQuery('parent', current.getUniqueValue());
prb.query();
if (prb.next()) {
GlideSysAttachment.copy('incident', current.getUniqueValue(), 'problem', prb.getUniqueValue());
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2024 09:37 AM
Thank you so much Brad, it worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2024 05:31 PM
Good news - you are welcome!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2024 06:19 AM
Hello @MohdF ,
- After Update Business Rule
(function executeRule(current, previous /*null when async*/) {
// Ensure that the incident has an associated problem record
if (current.problem_id && current.problem_id.changes()) {
var problemSysId = current.problem_id.sys_id;
var attachmentGr = new GlideRecord('sys_attachment');
attachmentGr.addQuery('table_sys_id', current.sys_id);
attachmentGr.query();
// Copy each attachment from the incident to the problem
while (attachmentGr.next()) {
GlideSysAttachment.copy('incident', current.sys_id, 'problem', problemSysId);
}
}
})(current, previous);
If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!