Transform map Scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2019 03:18 PM
Hi,
Can someone let me know why its importing record from excel.
Requirement: Ignore a record to be inserted if u_name field on source records is empty.
I have created onBefore scripts as below
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if(source.u_name == '' && action == 'insert'){
ignore = true;
}
})(source, map, log, target);
also i have onComplete script
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var gr = new GlideRecord ('cmdb_ci_ec2_instance');
gr.addQuery('state','!=','terminated');
gr.query();
while(gr.next()){
var src = new GlideRecord('ec2__load');
src.addQuery('u_instance_id',gr.object_id);
src.addQuery('sys_import_set.number',import_set.number);
src.query();
if(!src.next()){
gr.state = 'terminated';
gr.update();
}
}
var gr1 = new GlideRecord ('cmdb_ci_ec2_instance');
gr1.addNullQuery('u_i_project');
gr1.addQuery('state','!=','terminated');
gr1.addQuery('state','!=','terminating');
gr1.query();
while(gr1.next()){
gr1.state = 'error';
gr1.update();
}
})(source, map, log, target);
Another script is onAfter :
if(source.u_cost_center == "" ){
target.state = 'error';
target.cost_center = "";
target.update();
}
Once I load the data without u_name it's not inserting records, but if any other column u_i_project & u_cost_center has empty value then its inserting a recordsbut empty value as shown below.
Can someone help me why i am getting these records inserted?
Thanks,
Vignesh
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2019 03:28 PM
try changing below on onbefore script
source.u_name.toString()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2019 04:22 PM
Thanks for replying Mike,
Unfortunately it didnt help its still inserting a record. What other options do you think it might trigger this issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2019 04:29 PM
Can you try source.u_name.toString().trim(); Just to make sure source does not have empty strings.
Also what is the key you are matching on?
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2019 04:39 PM
Thanks, vkachineni !!