ポータルの画面からCSVインポートを行いたい

d-aizawa
Kilo Sage

コミュニティの皆様
いつもお世話になっております。

 

私はサービスポータルの画面からCSVデータをアップロードして、
テーブルにインポートしたいと考えております。

PDIでDataSouceを作成し、テーブル(Incidentは例です)にインポートできることは確認済です。

(設定内容はスクリーンショットをご確認ください)

 

イメージとしては

①Record Producerを作成
②Variables(TypeはAttachment)を追加

③Record Producer scriptで以下処理を記載

・DataSourceの添付ファイルにCSVを配置

・DataSourceのLoad All Recordsを実行

・Transform MapでTransformを実行

のような形で考えておりますが、③について、サンプルコードなど前例があればご教示頂きたいです。

よろしくお願いいたします。

 

▼Data Source

daizawa_0-1668158029510.png

▼CSV

daizawa_1-1668158047700.png

▼Groupテーブル

daizawa_2-1668158065009.png

▼Transform Map

daizawa_3-1668158087183.png

▼インポート後のIncident

daizawa_4-1668158110747.png

 

 

 

2 REPLIES 2

Joel Millwood2
Kilo Guru

Hi d-aizawa,

 

As an option, I would suggest that you create a flow to perform the following:

  1. Lookup the data source record (alternatively create / update the data source record if not present)
  2. Remove the previous attachments from this record (if any) so that you don't import old data
  3. Attach the new file to the data source record
  4. Trigger a Custom Flow Action to do the following in a script step:
    1. Lookup the transform maps for the import set table
    2. Load the data into the import set table
    3. Run the transform Map(s) to transform the data from the import set table into the target table(s)

Here is a code example for triggering a data source and its related transform maps:

var importSetTableName = '<name_of_import_set_table>';
var transformMaps = [];

// Lookup transform maps for a given import set table
var transformMapGr = new GlideRecord('sys_transform_map');
transformMapGr.addActiveQuery();
transformMapGr.addQuery('source_table', importSetTableName);
transformMapGr.orderBy('order');
transformMapGr.query();

while (transformMapGr.next()) {
    transformMaps.push(transformMapGr.getUniqueValue());
}

// Load the data into the import set table
var loader = new GlideImportSetLoader();
var importSetGr = loader.getImportSetGr(dataSourceGr);
loader.loadImportSetTable(importSetGr, dataSourceGr);
importSetGr.state = 'loaded';
importSetGr.update();

// Transform the data from the import set table into the target table
var transformWorker = new GlideImportSetTransformerWorker(importSetGr.sys_id, transformMaps.join());
transformWorker.setBackground(true);
transformWorker.start();