The CreatorCon Call for Content is officially open! Get started here.

Upload attachment from email to the existing Data source

vijay39
Giga Expert

HI Folks,

I have created a Data Source (Testexample.csv) and it has an attachment. My requirement is when ever service-now receives email (from inbound email action) that has an attachment also, i want to update the attachment in the Data source with this new one. I want to delete the already existing attachment in data source and want to attach the new attachment that has come up with email. I written the following code but in vain,

var dataSourceID = "e50bc6bbdb92bf80f0463ccb7c963476";

//Query the attachments for this data source and delete them
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name','sys_data_source');
gr.addQuery('table_sys_id',dataSourceID);
gr.query();

gr.deleteMultiple();

//Copy attachment from the Email to the Data Source
GlideSysAttachment.copy('sys_email',sys_email.sys_id,'sys_data_source',dataSourceID);

 

So can some one help me on this with code and clear explanation.

 

Regards,

Vijay

6 REPLIES 6

Hi, 

Work is getting done (deleting the existing attachment in data source and updating the data source with the new attachment that is coming from mail as expected)

But the problem i am not understanding is, when i check email , there the Target is showing empty and also when i scroll down to email logs, i could not see my inbound action processed. I see

Skipping 'Security Switch', did not create or update sys_data_source

Stop processing detected after executing script: Security Switch

(Seciurity Switch is the name given to Inbound action)

 

So why it is not getting triggered ? 

 

Regards,

Vijay

Hi Vijay,

I have the same requirement like you and I wanted to use existing data source and copy the attachment from email. I was able to delete the existing attachments from data source but I'm not able to copy new attachment that is coming from email.

Can you please let me know how are you passing sys_id of email dynamically in the following code?

GlideSysAttachment.copy('sys_email', <sys_email.sys_id>,'sys_data_source',dataSourceID);

Thanks!