How to create Import Sets - Data Sources using script in ServiceNow Scripts - Background
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2018 11:43 PM
Hello,
I want to create Import Sets - Data Sources with below setting using script:
How to create above Data Sources then Load All Records using script?
Thanks,
Tim
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2018 11:52 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2018 12:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2018 12:38 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2018 03:10 AM
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?
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