How to create Import Sets - Data Sources using script in ServiceNow Scripts - Background

Tim61
Kilo Contributor

Hello,

I want to create Import Sets - Data Sources with below setting using script:

find_real_file.png

 

How to create above Data Sources then Load All Records using script?

Thanks,
Tim

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Tim,

I would suggest following:

1) Have the data source ready in your instance, have transform map and field map ready

2) Now executing it will require following:

a) Create scheduled data import for this data source with active as false and run as system admin

b) use below script whenever you want to trigger the transform from background in global scope

var schImp_GR = new GlideRecord('scheduled_import_set');
schImp_GR.addQuery('name','<nameOfScheduledImportSet>');
schImp_GR.query();
if(schImp_GR.next()){
SncTriggerSynchronizer.executeNow(schImp_GR);

// for scoped app use below line

//gs.executeNow(schImp_GR);

}

 

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Could you provide a script to me about create a data source as below setting?

find_real_file.png

Thanks,

Tim

 

Hi Tim,

It is very simple. It is similar to inserting record into Data Source table with proper field and values.

just give proper field from data source with values you have

var gr = new GlideRecord('sys_data_source');

gr.initialize();

gr.name = '';

...

...

gr.insert();

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

1. Thanks a lot,I can create datasource using below script:

var gr = new GlideRecord('sys_data_source');

gr.initialize();

gr.name = '';

...

...

gr.insert();

How to use script command to Load All Records as below screen after created datasource?
find_real_file.png

 

2. I want to create below two Transform Map with above data source name Importtesting201806111700 using script:

Transform Map 1:
Name: Transtesting201806111721
Source table: Importtesting201806111700
Target table: u_computer_id
Field Maps:
Source field: u_computername
Target field: u_computer_name
Coalesce: true
Source field: u_computerid
Target field: name
Coalesce: false

Transform Map 2:
Name: Transtesting201806111746
Source table: Importtesting201806111700
Target table: u_relay_name
Field Maps:
Source field: u_value
Target field: name
Coalesce: false
Source field: u_computername
Target field: u_computer_name
Coalesce: true

How to create above two Transform Map using script in ServiceNow Scripts - Background?

Thanks,
Tim