- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2014 10:56 AM
Hi,
I'm trying to use a GlideRecord query to search for a document ID, but it doesn't appear to be working. Does anyone have an example of how to query for a Document ID?
Here's what I have so far.
var email = new GlideRecord('sys_email'); email.addQuery('sys_id',current.table_sys_id); email.query(); while (email.next()) { gs.log("Target record sys_id " + email.target_table + email.instance); gs.log("Attachment created by " + email.sys_created_by); gs.log("Attachment created at " + email.sys_created_on); gs.log("Attachment " + current.sys_id.toString()); }
The email.instance is the document ID field and it does not log anything.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2014 01:50 PM
The issue is the order that things are done.
1) You hit the Client Email button this creates an entry in the sys_email table (with no Target).
2) You add an attachment to the email - This creates the Attachment triggering your business rule (still no target).
3) You hit send the Target (instance) is updated on the email.
Second thought:
Business Rule
when: After
Table: sys_email
Condition: !current.instance.nil()
Script:
var instance = current.instance;
var targetTable = current.target_table;
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();
while(gr.next()){
gr.table_sys_id = instance;
gr.table_name = targetTable;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2014 01:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2014 01:50 PM
The issue is the order that things are done.
1) You hit the Client Email button this creates an entry in the sys_email table (with no Target).
2) You add an attachment to the email - This creates the Attachment triggering your business rule (still no target).
3) You hit send the Target (instance) is updated on the email.
Second thought:
Business Rule
when: After
Table: sys_email
Condition: !current.instance.nil()
Script:
var instance = current.instance;
var targetTable = current.target_table;
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();
while(gr.next()){
gr.table_sys_id = instance;
gr.table_name = targetTable;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2014 06:05 AM
Thanks, that seems to work. Making the business rule run after update does the trick.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2014 06:29 AM
Actually, I did one additional thing. With the condition set as !current.instance.nil() the attachments were being stripped before they were actually sent. I changed the condition to !current.instance.nil() && current.type == 'sent' which waits to strip the attachment from the email until after it has been sent to the recipient.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2014 01:00 PM
You said earlier it is set up in an "after" business rule.
Then you need to add a "current.update()" to save the changed current record.