Attachment not getting added to Data Source on submit of Request from service catalog.

ankurkhare
Kilo Contributor

I am trying to create a data Source from run script in workflow. The data source record is getting created but the attachment is not getting added from the service request once we submit the request along with attachment. Please assist.

Below is my code which I wrote in run script:

var gr=new GlideRecord('sys_data_source');
gr.name=gs.getUserDisplayName();
gr.import_set_table_name='u_source_data';
gr.file_retrieval_method="Attachment";
gr.type="File";
gr.format="Excel";
gr.header_row=1;
gr.sheet_number=1;
gr.insert();

The above code creates the record in data source form but the attachment is not there.

 

BR,

Ankur

 

1 ACCEPTED SOLUTION

No,

the sysID is a variable in the line...please do not put '' around it.

GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', sysID);

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

6 REPLIES 6

Allen Andreas
Administrator
Administrator

Hello,

There's nothing in your script that would copy the attachment...so not sure where in that code you felt it should?

If the attachment is already attached to the current record this script is running in, you could add this line after the insert line:

GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', 'data_source_sys_id');

So change your insert line to: var sysID = gr.insert();

That way you can use sysID later in the GlideSysAttachment like:

GlideSysAttachment.copy('table_name', current.sys_id, 'sys_data_source', sysID);

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank you very much Allen

I am able to find the attachment in the data source 🙂

ankurkhare
Kilo Contributor

Thanks for the reply Allen.

I am new to snow .

I have updated my code as below but still the attachment is not coming in the Data Source form. I could see the attachment in sc_req_item table and also the same in sys_attachment table

Please let me know if something more needs to be done?

var gr=new GlideRecord('sys_data_source');
gr.name=gs.getUserDisplayName();
gr.import_set_table_name='u_source_data';
gr.file_retrieval_method="Attachment";
gr.type="File";
gr.format="Excel";
gr.header_row=1;
gr.sheet_number=1;
var sysID = gr.insert();
GlideSysAttachment.copy('sc_req_item', 'current.sys_id', 'sys_data_source', 'sysID');

BR,

Ankur