attachment.uploaded event triggering and subsequent scripting

verdakosnett
Tera Expert

I have form on which i track who uploaded what attachment as in the screen capture below:

find_real_file.png

This works fine as long as the form is submitted but obviously it is no good if a user drags a file to the form. So, I registered an event as follows:

find_real_file.png

I then wrote a business rule:

find_real_file.png

and nothing happened....Where did I go wrong?

1 ACCEPTED SOLUTION

Yes as chuck mentioned, it should be an after BR. What is the field type of attachment_links and is it a custom field ?


View solution in original post

23 REPLIES 23

Thanks, it was a conflict due using doc pointer names used elsewhere. Once I used brand new names everything started working. The following shows how to capture attachment upload history using a business rule as per Abhinay's recommendations:


find_real_file.png


find_real_file.png


Hi ,
I tried with the same approach as mentioned above but the business rule is not fired. I want to update incident when attachment is updated corresponding to incident record.

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord("incident");
    gr.addQuery("sys_id", current.table_sys_id);
    gr.query();
	gs.log("===>record exists", gr.next());
    while(gr.next()) {
		gs.log("===>record glide", gr);
		//fi = gr.getElement('isAttachmentUpdated'); 
		gr.setValue('isAttachmentUpdated', 'Updated'); //custom field isAttachmentUpdated
        gr.update();
    }

    // Add your code here

})(current, previous);

condition = current.table_name == "incident"

Operation : After Insert/Update

 

Note: I'm able to receive the "record exists" debug as "true" but not able to get the log inside while loop. Please help me understand what is the issue fix as the custom field (isAttachmentUpdated) on incident is also not getting updated.

Abhinay Erra
Giga Sage

Glad you got this working.


jason45
Kilo Guru

There is an Attachments Related List that provides very similar functionality, and doesn't require additional logic to manage the entries in a separate table (for example if an attachment is removed from the incident / task, it will still show in the history table you have.

I realise this is responding to an old post, but you may want what is possibly a simpler solution, that has no technical debt.