- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2017 05:32 AM
Hi All,
We are having the below field map to map HOSTNAME from source table to Name in Target table. Now we want only for class "cmdb_ci_db_instance" in Source table the hostname which has like (ORACLE:CNSZIDC04) , we need to replace : with @ and set to name field in Target like(ORACLE@CNSZIDC04) . We have the below script , please guide.
Does it conflict with the existing Field Map.
I tried the below script it is not setting the Name by replacing : with @ .In logs I am getting correctly as Replaced String: ORACLE@CNSZIDC04
Still getting as
Code:
=====
CODE:
=======
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var sdb = source.u_cmdb_class_name;
if(sdb == "cmdb_ci_db_instance"){
var hnmd = source.u_hostname;
var resd = hnmd.replace(":", "@");
gs.log("Replaced String: "+resd);
target.name = resd;
}
})(source, map, log, target);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2017 05:48 AM
It looks to me like you may be running your code as an onStart Transform Script. I ran the following code in a Field Map, using the 'Use source script' option, and it worked as expected.
answer = (function transformEntry(source) {
var sdb = source.u_cmdb_class_name;
if(sdb == "cmdb_ci_db_instance"){
var hnmd = source.u_hostname;
var resd = hnmd.replace(":", "@");
gs.log("Replaced String: "+resd);
return resd;
} else {
return source.u_hostname;
}
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2017 05:48 AM
Hi Ravishankar,
You may remove out the field map and have name field set via transform map script
if ( sourceClassIsDesired ) {
}
else {
target.name = source.u_hostname;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2017 05:48 AM
It looks to me like you may be running your code as an onStart Transform Script. I ran the following code in a Field Map, using the 'Use source script' option, and it worked as expected.
answer = (function transformEntry(source) {
var sdb = source.u_cmdb_class_name;
if(sdb == "cmdb_ci_db_instance"){
var hnmd = source.u_hostname;
var resd = hnmd.replace(":", "@");
gs.log("Replaced String: "+resd);
return resd;
} else {
return source.u_hostname;
}
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2017 07:16 AM
Hi Justin,
Please let me know how do I stop inserting if Hostname value on the Database record doesn't follow the correct format (no colon separating the DB name from the Server)
an exception should be thrown and the record should not be loaded.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2017 08:24 AM
if (hnmd.indexOf(':') == -1) {
ignore = true;
}