- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2019 03:02 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2019 06:42 AM
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2019 05:35 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2019 10:17 PM
Thank you very much Allen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2019 10:18 PM
I am able to find the attachment in the data source 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2019 06:23 AM
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