how to use run script in transform map

zhanglixin
Tera Expert

zhanglixin_0-1673395871824.png

 

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @zhanglixin ,

If you want to make any validation then you can use transform script.

Ex: You can refer below example we can use run script for like this and many other validations.

 

(function transformRow(source, target, map, log, isUpdate) {
    var mail = source.u_email; //using source get the source fields
    if (mail.endsWith('@gmail.com') == true) {
        //do nothing here
    } else {
        error = true;
        source.sys_import_state_comment = 'gmail is not in correct format'; //comment will display like message when they sent invalid data in response
    }
})(source, target, map, log, action === "update");

 

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

4 REPLIES 4

zhanglixin
Tera Expert

actually  I mean when to use run script in transform map???

Hi @zhanglixin,

You can use the Script to transform the source field value to the target fields.

You can also use these script to ignore particular row transformation if source field value is empty or not meeting the required condition or to throw the error.

https://docs.servicenow.com/en-US/bundle/tokyo-platform-administration/page/script/server-scripting/...

https://developer.servicenow.com/dev.do#!/learn/learning-plans/tokyo/new_to_servicenow/app_store_lea...

 

Let me know if it helped.

 

Thanks,

 

newhand
Mega Sage

正式实施转换的时候才会执行这个脚本。

Please mark my answer as correct and helpful based on Impact.

Pavankumar_1
Mega Patron

Hi @zhanglixin ,

If you want to make any validation then you can use transform script.

Ex: You can refer below example we can use run script for like this and many other validations.

 

(function transformRow(source, target, map, log, isUpdate) {
    var mail = source.u_email; //using source get the source fields
    if (mail.endsWith('@gmail.com') == true) {
        //do nothing here
    } else {
        error = true;
        source.sys_import_state_comment = 'gmail is not in correct format'; //comment will display like message when they sent invalid data in response
    }
})(source, target, map, log, action === "update");

 

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar