Skip to content

Commit af88ba1

Browse files
ServiceNow – Automated Data Source Trigger (#2021)
* Create TriggerDataSource.README.md TriggerDatasource from script to load data * Create TriggerDataSource.js * Update TriggerDataSource.js
1 parent dc8f4ad commit af88ba1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The triggerDataSource() function eliminates the need for manually executing a Data Source from the UI.
It programmatically triggers the import of a predefined Data Source record and loads the associated data into an Import Set table.
2+
This function is typically used in:
3+
* Scheduled Script Executions
4+
* Flow Designer Actions.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
triggerDataSource: function() {
2+
3+
var dataSourceSysId = gs.getProperty('ds.tag.based.sys.id'); //Store the sysId of DataSource from system property
4+
5+
var grDataSource = new GlideRecord('sys_data_source');
6+
if (grDataSource.get(dataSourceSysId)) {
7+
var loader = new GlideImportSetLoader(); //OOB Method to load
8+
var importSetRec = loader.getImportSetGr(grDataSource);
9+
var ranload = loader.loadImportSetTable(importSetRec, grDataSource);
10+
importSetRec.state = "loaded";
11+
importSetRec.update();
12+
return importSetRec.getUniqueValue();
13+
}
14+
},

0 commit comments

Comments
 (0)