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.

I want to fetch location in work note field

PranavK27183203
Giga Contributor

In FSM module, I want to get agent current location to fetch and add in work note from user table.
Is there any property there so I can enable it and I can get latitude and longetude in user table

2 REPLIES 2

GlideFather
Tera Patron

Hi @PranavK27183203

 

what would be the scenario?

If you want to display such values, the work notes are not the best option. Imagine - the value is copied to WN and then somebody else adds another WN and the detail is lost or difficult to find again.

It would be also better for filtering the data and eventual reporting.

 

Wouldn't it make sense maybe to add a field to display that? It can be read-only or under some tab/section... 

_____
No AI was used in the writing of this post. Pure #GlideFather only

WillieW
Tera Expert

You could use a business rule defined on the table that runs Before for Insert and Update.  And the following script in the Advanced tab.

 

(function executeRule(current, previous /*null when async*/) {

	// get latitude and logitude of the current user
	var usrID = current.assigned_to.toString(); // or Agent name if on the record being created/updated
	var usr = new GlideRecord('sys_user');
	usr.addQuery('sys_id', usrID);
	usr.query();
	if (usr.next()) {
		var lat = usr.location.latitude;
		var lon = usr.location.longitude;
//		gs.info('User : ' + usr.name + ', lat: ' + lat + ', long: ' + lon);
		current.work_notes = 'Agent: ' + usr.name + ', latitude: ' + lat + ', longitude: ' + lon;

	}

})(current, previous);

 

(Tested in a BR for the incident table)

 

A system property is not going to fetch a user's location latitude and longitude values that I'm aware of.