- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2017 12:06 AM
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)
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";
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2017 01:47 AM
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 );
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2017 01:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2017 01:22 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2017 01:47 AM
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 );
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2017 04:14 AM
Ok Thanks Gurpreet for your help. I have written the required scripts .