How to copy attachment from one record to another record

mark141230
Tera Expert

Hi Everyone,

I have a requirement, the scenario is that upon insert the attachment in the Customer Service application that I have created will automatically copied to the incident record.

the case is that if an agent is about to submit a ticket from the customer service application, once he indentified that this is an incident it will automatically create an incident ticket, I was successful on that part but the problem is that the attachment is not included once the incident record is created. I have this code but it is not working, hope someone can help me.

Business Rule

Table: Customer Service

When to Run: After / Insert

Script:

(function executeRule(current, previous /*null when async*/) {

var ritm = new GlideRecord('x_glti_incident_ma_incident_management_table');

ritm.addQuery('x_glti_customer_se_customer_service_ticket',current.sys_id);

ritm.query();

while(ritm.next()){

GlideSysAttachment.copy('x_glti_customer_se_customer_service', current.sys_id, 'x_glti_incident_ma_incident_management_table', ritm.sys_id);

}

})(current, previous);

Many thanks in advance

10 REPLIES 10

vinothkumar
Tera Guru

I believe the problem here is   that there are two business rule, one for inserting incident record after the call is submitted and another is for copying attachment.



You have to change the order and I guess the issue is that, it might execute at the same time,so may be the sys_id won't be available in the the system.



Try by checking log as gs.log(ritm.sys_id); so it would be helpful.


Hi Vinoth,



I think that is not the problem because I have another BU runs at the same just to copy the ticket number of incident after insert and the query I used is the reference number form the customer service application.


mark141230
Tera Expert

I Hope Someone can hep me


I am not sure why it is not working, maybe this 2 application is a scope application since i just made it from scratch


I suspect the scope also. Rest is quite straight forward.


-Anurag