Throw Exceptions for Field Mapping in Transform Map

Mrman
Tera Guru

Hi All,

I have critical requirement about Transforming the data to the target table (cmdb_ci) . We have already created field maps for the corresponding target field and also few Transform scripts .

Now the requirement is to throw exceptions by logging it using a script . For example we have the following field maps .I have highlighted   some fields for which exception has to be done.

Now I want to know how do I write script for already created direct field mappings like cinum , hostname . Where can I write the script by using the below mentioned script include. Any Response will be really helpful.

Please throw exceptions for the following conditions (and do no create the record):

1. Blank CINUM

2. Blank or space in HOSTNAME

3. Invalid HOSTNAME (not a valid pipeline or operational value if App/Web/DB Inst)

4. Invalid STATUS (not 'Not Ready', 'Operating', 'Decommissioned', 'Return_Owner', or 'Withdrawn')

5. Invalid SERVICETYPE (not Gold, Silver, Bronze, or blank)

6. Invalid ENVIRONMENT (not Production, Pre-production, UAT, Development, or blank)

7. Blank or invalid PRIMARY_AFFECTED_COUNTRY (based on Location table)

8. Blank SERIALNUM (if CI_Server_Type=Physical)

9. Blank MANUFACTURER (if CI_Server_Type=Physical)

10. Blank MODEL (if CI_Server_Type=Physical)

find_real_file.png

We have a common script include where we call to log the warnings and messages. Like below

// code for logging error messages
gs.include('data_load_logs_asset');
var scinc = new data_load_logs_asset();
var logmessage ='';
var topic ='';
var messagetype = '';

topic = serial;

After calling this we use if and else to log .

else {

    logmessage =logmessage + "*-*" + "Warning: UNSPSC "+itemId+" is not present for Hardware feed in the Data.";

    messagetype = messagetype + "*-*" + "Warning";

  }

1 ACCEPTED SOLUTION

Hi Ravi,



You need to use existing field map but also add transform scripts for for the validations. First transform script will validate the data and then the data will be transferred to target table with the help of field mappings.


Script seems to be okay... add below statement to add logs.


..


..


var num = source.u_cinum;


if(num ==""){



  ignore = true;


  logmessage =logmessage + "*-*" + "Warning: The cinum is blank.";


  messagetype = messagetype + "*-*" + "Warning";


log.info(logmessage );


}


View solution in original post

8 REPLIES 8

Ok Thanks Gurpreet.



So I can just leave the existing field maps as is which are highlighted below and create new transform scripts for exception and logs right. Please confirm.



find_real_file.png


Hi Gurpreet,



Please confirm if the below transform script is fine , also I have not deleted the existing field mapping for cinum . please confirm.



(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {



// code for logging error messages


gs.include('data_load_logs_asset');


var scnum = new data_load_logs_asset();


var logmessage ='';


var topic ='';


var messagetype = '';



topic = serial;



var num = source.u_cinum;


if(num ==""){


 


  ignore = true;


  logmessage =logmessage + "*-*" + "Warning: The cinum is blank.";


  messagetype = messagetype + "*-*" + "Warning";


}



})(source, map, log, target);


Hi Ravi,



You need to use existing field map but also add transform scripts for for the validations. First transform script will validate the data and then the data will be transferred to target table with the help of field mappings.


Script seems to be okay... add below statement to add logs.


..


..


var num = source.u_cinum;


if(num ==""){



  ignore = true;


  logmessage =logmessage + "*-*" + "Warning: The cinum is blank.";


  messagetype = messagetype + "*-*" + "Warning";


log.info(logmessage );


}


Ok Thanks Gurpreet for your help. I have written the required scripts .