The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Transform Script to assign a replaced string

Mrman
Tera Guru

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.

find_real_file.png

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

find_real_file.png

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);

1 ACCEPTED SOLUTION

Justin Abbott
Giga Guru

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);


View solution in original post

7 REPLIES 7

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);


Yes, you could put that code in an onBefore script.


Hi Justin,



Could you please respond.