Transform map should not update if one record is missing value.

suryan
Kilo Expert

In Transform map iam updating the records(no inserting). If ST validation id is empty then that record is not updating, it is working fine. My requirement is if

1)I'am updating 1000 records if 999 records is having ST.validation_ID, then i don't want to update single record in transform map,(the transform map should not be happen for single record out of 1000 i.e if 1 record is missing validation.ID whole 1000 records should not update.) means the transform map option should not complete.

2)I'am getting messages in system log, is it possible to get the message while doing transform map so that user be able to know that records are not updating because of empty validation ID.

1 ACCEPTED SOLUTION

is the source field name is ST.validation_ID. Can we replace the dot after ST with underscore like ST_validation_ID and also in you if condition there is a comma after ST.validation_ID. Can you please remove that and try. Can we something like this with nil() function.



(function transformRow(source,map, log, target) {


  if(action == 'insert'){


        ignore = true;


  }


  if(source.ST_validation_ID.nil()){


            ignore = true;


          error = true;


          var error_message='Supplier Validation Results field is blank, Please update the field to   complete the update';


          log.info(error_message);


  }


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


View solution in original post

20 REPLIES 20

Shishir Srivast
Mega Sage

Can we try to get the count of validation.ID field using GlideAggregate with onStart transform scripts and then compare with the actual count, if record doesn't match then let's have the ignore = true;



http://wiki.servicenow.com/index.php?title=GlideAggregate#gsc.tab=0


http://wiki.servicenow.com/index.php?title=Transform_Map_Scripts#Transformation_script_variables



I didn't try but let's see if it helps in this way.


var actualcount = new GlideAggregate('Source_table_name');


actualcount.addAggregate('COUNT');


actualcount.query();


var num = 0;


var actualnum = 0;


if(actualcount.next()){


actualnum = actualcount.getAggregate('COUNT');


var count = new GlideAggregate('Source_table_name');


count.addQuery('validation_field_name', null);


count.addAggregate('COUNT');


if(count.next())


num = count.getAggregate('COUNT');


}


if(num != actualnum)


ignore = true;


bernyalvarado
Mega Sage

It feels like we responded this in a different thread some days ago .



1) yes. Using onStart script. Shishir is right in regards that you just need to validate if at least one of the records it's missing the value. A GlideAggregate is not really needed for this. You can even just do a query over a source table and see if there's at least one value where validation_ID is missing.



2) I don't think there's a way to show a message to the end user doing an import/tranform unless something like a gs.addInfoMessage works.



Thanks,


Berny


Hi berny,



If one record is missing whole update has to be aborted, but here only missing values are not updated, remaining it is updated. I want all records not to be updated still if one record is missing the value .


I think, that's why we have to use ignore script variable with onStart() script to skip the entire transformation.


ignoreFlagA boolean variable ("true" or "false") where true in onStart scripts will cause the entire transformation process to be skipped. Setting it to true in onBefore scripts will cause the current row transformation to be skipped, and will continue to process the remaining rows. Default is "false".
if (source.u_user_name.nil()){ ignore = true; }