Importing Data from Portal via Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 09:18 PM
Let me describe my requirements:
I need to allow an end user to visit the CSM Portal and fill out a form where they upload a spreadsheet of data. The spreadsheet template will be provided by us, as we need to collect particular information.
I then want to take this spreadsheet and automatically upload it into the system. I figured I could use a Business Rule on the csm_order_case table to find the attachment:
var myAttachment = new GlideRecord('sys_attachment');
myAttachment.addQuery('table_sys_id', current.getUniqueValue());
myAttachment.addQuery('content_type', 'application/xlsx');
myAttachment.query();
And then beyond this, create a new data source, table and import set. I have begun this process by creating the data source and extending a master table which will define the appropriate columns:
while (myAttachment.next()) {
var newSource = new GlideRecord('sys_data_source');
newSource.initialize();
newSource.name = myAttachment.name;
newSource.file_retrieval_method = 'Attachment';
newSource.format = 'Excel';
newSource.type = 'File';
newSource.import_set_table_name = myTableName;
newSource.insert();
var tc = new GlideTableCreator(myTableName , myTableName);
if(typeof extends_table != 'undefined') tc.setExtends('u_xlsx_import');
tc.update();
var newSet = new GlideRecord('sys_import_set');
newSet.initialize();
I got up to the part where I create a new import set, but now I am becoming uncomfortably aware that this may not be so easy. I have done some searching and am quite stuck.
My question is, now that I have created the source and table, how do I script the creation of an import set? How do I tell it to use "myAttachment" and how does the upload process work from here?
Thanks in advance for any assistance!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2017 03:45 AM