We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Create data source using script

Alex153
Tera Contributor

Hi guys,

Does anybody have a script to create data source record?

I found the following but it should be modified

  
   var type = {};
type.schedule = 'u_imp_tmpl_u_term_phr_empl_mvs_ids'; //Display name for scheduled import  -- eb9f2dae6f46a60051281ecbbb3ee4a5
type.table = 'u_imp_tmpl_u_term_phr_empl_mvs_ids'; //Import table name

gs.log('0. Process File Start');

if(type.schedule != '' && type.table != '') {
    gs.log('1. Setting up data source');
    current.name = type.schedule + '_' + gs.nowDate(); //append date time to name of data source for audit
    current.import_set_table_name = type.table;
    current.import_set_table_label = "";
    current.type= "File";
    current.format = "CSV";  //"Excel CSV (tab)";
    current.header_row = 1;
//    current.file_retrieval_method = "Attachment";
    current.file_retrieval_method = "HTTPS";
    current.data_source.url = "storage.googleapis.com";
    current.pathParams.url = "/gcp_bucket_ca/sobject_test_export3.csv";

    var myNewDataSource = current.insert();

}
1 ACCEPTED SOLUTION

Vasantharajan N
Tera Sage

Please post your actual requirement / issue to address it. 

Made changes that creates the data source record

var gr = new GlideRecord("sys_data_source");
gr.initialize();


var type = {};
type.schedule = 'u_imp_tmpl_u_term_phr_empl_mvs_ids'; //Display name for scheduled import -- eb9f2dae6f46a60051281ecbbb3ee4a5
type.table = 'u_imp_tmpl_u_term_phr_empl_mvs_ids'; //Import table name

gs.log('0. Process File Start');

if (type.schedule != '' && type.table != '') {
gs.log('1. Setting up data source');
gr.name = type.schedule + '_' + gs.nowDate(); //append date time to name of data source for audit
gr.import_set_table_name = type.table;
gr.import_set_table_label = "";
gr.type = "File";
gr.format = "CSV"; //"Excel CSV (tab)";
gr.header_row = 1;
// current.file_retrieval_method = "Attachment";
gr.file_retrieval_method = "HTTPS";
gr.scp_server = "storage.googleapis.com";
gr.file_path = "/gcp_bucket_ca/sobject_test_export3.csv";

var myNewDataSource = gr.insert();
gs.print(myNewDataSource);

}


Thanks & Regards,
Vasanth

View solution in original post

2 REPLIES 2

Vasantharajan N
Tera Sage

Please post your actual requirement / issue to address it. 

Made changes that creates the data source record

var gr = new GlideRecord("sys_data_source");
gr.initialize();


var type = {};
type.schedule = 'u_imp_tmpl_u_term_phr_empl_mvs_ids'; //Display name for scheduled import -- eb9f2dae6f46a60051281ecbbb3ee4a5
type.table = 'u_imp_tmpl_u_term_phr_empl_mvs_ids'; //Import table name

gs.log('0. Process File Start');

if (type.schedule != '' && type.table != '') {
gs.log('1. Setting up data source');
gr.name = type.schedule + '_' + gs.nowDate(); //append date time to name of data source for audit
gr.import_set_table_name = type.table;
gr.import_set_table_label = "";
gr.type = "File";
gr.format = "CSV"; //"Excel CSV (tab)";
gr.header_row = 1;
// current.file_retrieval_method = "Attachment";
gr.file_retrieval_method = "HTTPS";
gr.scp_server = "storage.googleapis.com";
gr.file_path = "/gcp_bucket_ca/sobject_test_export3.csv";

var myNewDataSource = gr.insert();
gs.print(myNewDataSource);

}


Thanks & Regards,
Vasanth

Thanks a lot for help!!