Attachment on multiple tasks

sry
Giga Guru

Hi, i have a requirement where user needs to attach one document(pdf) on multiple tasks like around 100 incidents.

could anyone please help me!

thanks,

sry

1 ACCEPTED SOLUTION

Hello sry,

So, me recommendation is simple:

  • From those 100 incidents, manually attach the file to one of them
  • Go to the sys_attachment table, locate the file that you added, by filtering records where:
    • table name = incident
    • table sys id = your incident sys_id
  • Create a fix script with the following code:

    var orig_incident_id = "<sys_id of the incident where you added the attachment>";
    copyAtt(orig_incident_id);
    function copyAtt(orig_incident_id){
    	var gr = new GlideRecord("incident");
    	gr.addEncodedQuery("<add your query to pick the other 99 incidents");
    	gr.query();
    	var counter = 0;
    	while(gr.next()){
    		new GlideSysAttachment().copy("incident", orig_incident_id, "incident", gr.sys_id);
    		++counter;
    	}
    	gs.info("copied attachment to " + counter.toString() + " records");
    }​

     

This should do the trick!!

Please, if this answer is relevant for you, please mark it as correct and helpful.

Thanks,

Filipe

View solution in original post

6 REPLIES 6

Hello sry,

So, me recommendation is simple:

  • From those 100 incidents, manually attach the file to one of them
  • Go to the sys_attachment table, locate the file that you added, by filtering records where:
    • table name = incident
    • table sys id = your incident sys_id
  • Create a fix script with the following code:

    var orig_incident_id = "<sys_id of the incident where you added the attachment>";
    copyAtt(orig_incident_id);
    function copyAtt(orig_incident_id){
    	var gr = new GlideRecord("incident");
    	gr.addEncodedQuery("<add your query to pick the other 99 incidents");
    	gr.query();
    	var counter = 0;
    	while(gr.next()){
    		new GlideSysAttachment().copy("incident", orig_incident_id, "incident", gr.sys_id);
    		++counter;
    	}
    	gs.info("copied attachment to " + counter.toString() + " records");
    }​

     

This should do the trick!!

Please, if this answer is relevant for you, please mark it as correct and helpful.

Thanks,

Filipe

thank you so much Felipe, this worked.