Is it possible to access scratchpad in transform scripts??

asoni1
Kilo Contributor

Is it possible to access scratchpad in transform scripts??

I have a requirement, where in I need to compare target table records with the input records and mark the unwanted records in target table as inactive 

 

Please recommend.

10 REPLIES 10

Varsha Jadhav1
Giga Expert

asoni1
Kilo Contributor

I will elaborate on my query.

 

I am inserting records to import set via Ansible Scripts. I have a use case in which I am inserting 2 records to the import set -> Record 1 and Record 2.

The target has say 4 records at the moment, (Record 1, Record 2, Record 3 and Record 4). So i want to take care of extra records in the target now.

 

However, I don't want to delete it rather mark it as inactive. I want to minimise hits to the database to achieve this to optimise performance as well. I hope my way of explaining is not confusing.

 

Please advise

You can use On start transform script to check the target table for Record3 and Record4 and inactivate them.

find_real_file.png

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
	
	// Add your code here
	gs.log("Log 1 "+source.getRowCount());//number of rows you have in the staging table
	gs.log("Log 2 "+source.getLocation());//-1. The first row has not been read yet
	/*
	Write Logic to check for Record 3 and Record 4 by reading the target table and set required rows to inactive
	while(source.next()){
		var xyzGr = new GlideRecord('targetTableName');
		xyzGr.addQuery('targetColumn','!=',source.getValue('compareColumn'));//Write your own condtion
		xyzGr.query();
		if(xyzGr.next()){
		  ......
		  .....// Write logic to inactivate the record
		  ......
		}
	}
 	*/
	source.setLocation(-1);//***Important
	
})(source, map, log, target);

asoni1
Kilo Contributor

Thanks ARG.

 

I am not sure how these events should work, but when I run using onStart event and I try to insert 3 records via ansible, I see it making 3 entries in the logs and it states that row count is 1

 

just executing below lines of code onStart event:

 

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

gs.log('row count: '+ source.getRowCount() + 'and row value : ' + source.getValue('u_question_text'));

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

 

I can see that your question has been answered in another thread. Please close this thread by marking this answer as correct. So that this can be moved to the answered category.  

https://community.servicenow.com/community?id=community_question&sys_id=04e5b38ddb577f44fff8a345ca96...