---
sourceDocument: Yokohama データと自動化
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/yokohama/integrate-applications

 Release :

    - yokohama

ft:locale :

    - ja-JP

ft:publication_title :

    - Yokohama データと自動化

ft:clusterId :

    - crint

bundleId :

    - crint

workflow :

    - Creator


---

# 変換マップへの onBefore スクリプトの追加

# 変換マップへの onBefore スクリプトの追加 {#ariaid-title1}

* リリースバージョン: Yokohama
* 
* 更新日 2025年01月30日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：2分

onBefore 変換マップスクリプトを作成して、新しいレコードの sys_id をソースからターゲットインスタンスにコピーします。2 番目の onBefore 変換マップスクリプトを作成して、一意の値が同じで sys_id 値が異なるターゲットインスタンスのレコードを識別します。

## 始める前に

必要なロール：admin

## 手順

1. 作成したテーブル変換マップレコードを開きます。
2. \[変換スクリプト\] 関連リストで、\[新規\] をクリックします。
3. \[時期 (When)\] フィールドで、\[onBefore\]を選択します。
4. 次のスクリプトを入力します。  

       if (action == "insert") {target.setNewGuidValue(source.u_sys_id); }

5. \[送信\] をクリックします。
6. \[変換スクリプト\] 関連リストで、\[新規\] をクリックします。
7. \[時期 (When)\] フィールドで、\[onBefore\]を選択します。
8. 次の \[スクリプト\] を入力します。  

       /** 
       * This script queries for a uniquely identifying value of the referenced record and then 
       * updates the target reference field with the sys_id of the matching target record.
       * This sample assumes:
       * 1) The target table contains an assigned_to field which is a reference field.
       * 2) The reference field references the User [sys_user] table.
       * 3) You can use the email field to uniquely identify users. Alternatively you
       *    could use the user_name field.
       */
       var ref = new GlideRecord("sys_user"); //Replace sys_user with any reference table
       ref.addQuery("email", source.email); //Replace email with any unique field
       ref.query();
       if(ref.next()){
          target.assigned_to = ref.sys_id; //Replace assigned_to with any reference field
       }

9. \[送信\] をクリックします。
**前のトピック:** [変換マップを作成](https://servicenow-prod.fluidtopics.net/B05zacQXHt761FYQeASV_Q "変換マップは、インポートセットのフィールドと既存の ServiceNow テーブルのフィールド (インシデント [incident] やユーザー [sys_user] など) の関係を決定する一連のフィールドマップです。")  
**次のトピック:** [CSV 形式のファイルからのデータの取得](https://servicenow-prod.fluidtopics.net/749mllnW~qn0jNpfcPzxMA "このメソッドでは、HTTPS データソースを使用して別のインスタンスからデータをインポートし、インポートする行を含む CSV 形式のファイルを返します。")

