- 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 08:27 AM
Hi ,
Please let me know if I need to write a new OnBefore transform script for this? I have already written Source script in Field map as below. Please suggest
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);
//target.name = resd;
return resd;
}
else{
return source.u_hostname; // return the value to be put into the target field
}
})(source);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2017 08:32 AM
Yes, you could put that code in an onBefore script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2017 08:23 AM
Hi Justin,
Could you please respond.