- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2015 10:15 AM
Hi...
I've researched the wiki and I believe I have a Business Rule that should work for my requirement, but it is not.
I've used this Wiki article:
copy attachments from one task to another
To build this - However, it is not working. Any suggestions? Thank you!
(Note: We have a custom 'alert' table that was implemented before 'event mgmt' was created.
Alerts are inserted into this table; the NOC then creates Incidents off of these Alerts.
So, on the Alert record there is a custom field 'u_incident' which contains the number of the Incident that is generated from the Alert.
the Alert is in the related list on the only created Incident.)
==============
function onAfter(current, previous) {
var gr = new GlideRecord('u_alert'); //query the customer alert table
gr.addQuery('sys_id', current.u_incident); //look for the sys_id of the current incident record in the 'u_incident' field on the Alert record
gr.query();
while(gr.next()) {
GlideSysAttachment.copy("incident", current.sys_id, "u_alert", gr.sys_id); //copy the attachment to the current incident from the alert record that was queried
gr.update();
}
}
===============
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2015 10:55 AM
Ok - so there's something else going on.
I changed the business rule to pull the attachment 'on update' and it works with this script:
var gr = new GlideRecord('u_alert');
gr.addQuery('u_incident', current.sys_id);
gr.query();
while(gr.next()) {
GlideSysAttachment.copy("u_alert", gr.sys_id, "incident", current.sys_id);
gr.update();
}
}
The reason the on 'insert' isn't working has something to do with the face we're running the script from a UI page 'processor' instead of directly from the UI action. I have to figure out how to have the UI page do it vs. just the UI action.
Thank you all for responding and your assistance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2015 10:36 AM
Then the script will be changed to :
GlideSysAttachment.copy("u_alert", gr.sys_id, "incident", current.sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2015 10:42 AM
Hi Mani -
Yes, I already tried this - isn't working.
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var gr = new GlideRecord('u_alert'); //query the customer alert table
gr.addQuery('u_incident', current.sys_id); //look for the sys_id of the current incident record in the 'u_incident' field on the Alert record
gr.query();
while(gr.next()) {
GlideSysAttachment.copy("u_alert", gr.sys_id, "incident", current.sys_id);
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2015 10:43 AM
try this: GlideSysAttachment.copy("u_alert", current.sys_id, "incident", gr.sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2015 10:45 AM
Hi Victor - I'll try that, but isn't this saying that the alert is the current record? I'm querying from the Incident which is the current record and the variable gr represents the alert table that I'm actually querying.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2015 10:55 AM
Ok - so there's something else going on.
I changed the business rule to pull the attachment 'on update' and it works with this script:
var gr = new GlideRecord('u_alert');
gr.addQuery('u_incident', current.sys_id);
gr.query();
while(gr.next()) {
GlideSysAttachment.copy("u_alert", gr.sys_id, "incident", current.sys_id);
gr.update();
}
}
The reason the on 'insert' isn't working has something to do with the face we're running the script from a UI page 'processor' instead of directly from the UI action. I have to figure out how to have the UI page do it vs. just the UI action.
Thank you all for responding and your assistance!