Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need Most Recent Discovery to update in Data Source

Saib1
Tera Guru

Hi ,

We have the excel file contain below data.

 

find_real_file.png

Created transform map to update the table based on the excel sheet and u_vm coalesce is true 

We need to update the Most Recent Discovery to be updated based on the data on the excel sheet. If there is no update , and excel sheet contain data it should get updated .  

How to implement?

find_real_file.png

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi @Shohaib 

Just saw your recent comment, what I have suggested should work for you. If not you can try with a Transform Script as below:

Write a On After Transform Script and use the script as below:

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

	// Add your code here
	var sourceVM = source.u_vm.toString();
	var gr = new GlideRecord('Give your target Table Name here');
	gr.addQuery('name',sourceVM);
	gr.query();
	if(gr.next()){
		target.last_discovered = new GlideDateTime();
		target.update();
	}else{
		ignore=true;
	}

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

Screenshot for reference below:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

8 REPLIES 8

shloke04
Kilo Patron

Hi @Shohaib 

Just saw your recent comment, what I have suggested should work for you. If not you can try with a Transform Script as below:

Write a On After Transform Script and use the script as below:

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

	// Add your code here
	var sourceVM = source.u_vm.toString();
	var gr = new GlideRecord('Give your target Table Name here');
	gr.addQuery('name',sourceVM);
	gr.query();
	if(gr.next()){
		target.last_discovered = new GlideDateTime();
		target.update();
	}else{
		ignore=true;
	}

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

Screenshot for reference below:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

let me try the above script .

Scenario is 

find_real_file.png

Thanks Shloke .

The above code worked for me.

Hi Shloke,

 

On the below code you sent to me. I just applied it. It is working fine. And blank record is getting created after this  transform script put in my system.

 

var sourceVM = source.u_vm.toString();
	var gr = new GlideRecord('Give your target Table Name here');
	gr.addQuery('name',sourceVM);
	gr.query();
	if(gr.next()){
		target.last_discovered = new GlideDateTime();
		target.update();
	}else{
		ignore=true;
	}