Update comments with attachment added

pushparaj
Mega Contributor

Hi all,

I want comments to be updated in requested item when an attachment is attached with the details like :

Attachment added to $RITMNumber$.

File name : $Filename$ by $Createdby$ at $created$

I would prefer a insert Business rule. So when attachment is added from portal also it would trigger.

so should i write the business rule on "sys_attachment" table or "sc_req_item" table.

Note: sys_attachment has no reference fields and just saving attachment with the table name in which its added into.

also can you please help me with the script for Business rule.to attain the infomation in comments like item number date etc..

Thank you .

1 ACCEPTED SOLUTION

Deepak Kumar5
Kilo Sage

Add a insert BR in Attachment Table with condition that current.table_name == "sc_req_item"


BR:


updateRecordForAttachment();  


function updateRecordForAttachment(){  


var gr = new GlideRecord(current.table_name);  


    if(gr.get(current.table_sys_id)){  


  gr.work_notes = "Attachment: " + current.file_name + " has been attached.";  


  gr.update();  


    }  


}  


View solution in original post

6 REPLIES 6

Deepak Kumar5
Kilo Sage

Add a insert BR in Attachment Table with condition that current.table_name == "sc_req_item"


BR:


updateRecordForAttachment();  


function updateRecordForAttachment(){  


var gr = new GlideRecord(current.table_name);  


    if(gr.get(current.table_sys_id)){  


  gr.work_notes = "Attachment: " + current.file_name + " has been attached.";  


  gr.update();  


    }  


}  


Thats working like a pro, but how do i attach the requested item number(RITM) and created by and created fields into this comments.
how to access those fields.


gr.work_notes = "Attachment: " + current.file_name + " has been attached by " + currentUser.getDisplayName() + " at " + gs.now() + " to " + gr.number;



Attachment: New Text Document.txt has been attached by System Administrator at 2016-11-30 to RITM001023


This has been very helpful.

I like to take it one step further and update the state of the item (or in my case the incident) as well but I can't get it to work.

Can you assist me on that?