Query for Document ID

amkatulak
Giga Expert

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.

1 ACCEPTED SOLUTION

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();


}


View solution in original post

16 REPLIES 16

Adding current.update() did not seem to help.


Thanks


Correct, same for us.


When the integrated email client is used for any task-table based record and a file is attached, that file will not show up as attachment on the task-table record.



Do you have an idea how to differentiate the attachments? (if they were attached to the task directly or sent via email)