Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

テーブル変換マップ 変換スクリプトでのメールアドレスチェックについて

NaoyaT
Tera Expert

こんにちは。知識不足で恐縮ですが、アドバイスいただけますと幸いです。

 

テーブル変換マップの変換スクリプトにて、タイミング「onbefore」でスクリプトを作成しています。
「質問の正規表現(question_regex.list)」のOOTBである「Email」の正規表現を利用して、
ソーステーブルのメールアドレス(u_group_email)が正規表現の形となっているかどうかをチェックしたいです。
正規表現の形になっていれば処理は流れ、正規表現の形になっていなければ処理を無視するようにしたいです。
以下スクリプトは「Email」の正規表現を直接変数に入れて実行しようとしていますが、うまくチェックができません。
ソーステーブルのメールアドレスが指定の正規表現通りの形となっているかどうかチェックする方法があればご教示いただきたいです。

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    // メールの形式が決まった正規表現の形式になっていない場合はテーブルの更新を行わない
    // グループのメールチェック
    gs.info('*********** グループメールチェック');
    var regexPattern = "^(?![\.])[a-zA-Z0-9!#$%*\/?|^{}`~&'\+\-=_.]+(?<![.]+)@(?![\.-])[a-zA-Z0-9-_\.]+(\.[a-zA-Z0-9_]+)$";

    // チェック対象のメールアドレスを取得。
    var emailToValidate = source.u_group_email;
    if (JSUtil.notNil(emailToValidate)) {
        // 文字列を正規表現として認識。
        var reg = new RegExp(regexPattern);
        // メールがパターンと一致するか確認、true/falseを返す。
        var isValid = reg.test(emailToValidate);

        if (!isValid) {
            log.warn('不正なメール形式のため無視。取込スキップ: ' + source.u_group);
            ignore = true;
        }
    }
})(source, map, log, target);

 

7件の返信7

@NaoyaT 

Thank you for marking my response as helpful.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@Ankur Bawiskar 

 

Thank you.

I tried it, but I encountered the following syntax error:

 

-error point-
“var re = new RegExp(pattern);”

 

-import set log-
SyntaxError: Invalid quantifier ? (sys_transform_script.67fb74323b1a8b105e35989704e45aa0.script; line 55)

 

-system log-
com.glide.script.RhinoEcmaError: Invalid quantifier ?
sys_transform_script.67fb74323b1a8b105e35989704e45aa0.script : Line(55) column(0)
52: return;
53: }
54:
==> 55: var re = new RegExp(pattern);
56: if (!re.test(email)) {
57: log.warn(‘Email format does not match. Import skipped: ’ + source.u_group);
58: ignore = true;
Stack trace:
at sys_transform_script.67fb74323b1a8b105e35989704e45aa0.script:55 (runTransformScript)
at sys_transform_script.67fb74323b1a8b105e35989704e45aa0.script:65

 

Regards,
Noaya.T

@NaoyaT 

are you sure you gave the correct record sysId for that regex record?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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