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

Brian Hoban
Tera Contributor

I'm a bit curious on why you would want to update the most recent discovery value, as this is clearly a data import, and typically you want to use that field for Discovery or Service Graph Connectors exclusively.

 

That being said, if you are determined to update the field, the field name is "last_discovered" (Most Recent Discovery is the label). I would script the result like the following:

var gt = new GlideDateTime();
answer = gt.toString();

(you may not even need to cast it to a string)

 

Also, you likely also want to provide a Data Source if you are setting the last_discovered date. You also may want to set a scripted "first_discovered" field to be set like the above if it doesn't already exist. That would set a consistent behavior with Discovery & Graph Connectors.

As a follow-up, an even better approach would be to leverage the IRE with your transform.

 

Instructions can be found here:

 

https://community.servicenow.com/community?id=community_blog&sys_id=7e3fb6d5db5afb00fece0b55ca9619e3

 

 

Hi Brian,

Similar like Discovery , i am trying to do in Transform Map.

we have set u_vm as coalese as of now .

Need a Transform Script to check if the data is present in the excel sheet and target table.

If the data is there on the Source table and Target table then we need the most_recent_discovery field to be updated with today's date .

 

shloke04
Kilo Patron

Hi,

Ideally, This field will be set by the sensor scripts during Identification phase after all the necessary fields which were found are updated in the database.

Can you explain the use case on why you need to update it manually here?

If you still need to go down this path, then you can create a Field Map and select Target Field as "Most recent Discovery" and update it as shown below:

answer = (function transformEntry(source) {

	// Add your code here
	var gr = new GlideDateTime();
	return gr; // return the value to be put into the target field

})(source);

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