Passing a record's sys_id when navigating to a Map Page upon clicking a UI Action

Jack Hoblyn
Tera Contributor

I have created a UI action which plots a records coordinates on a map page using a marker.

I am trying to pass the sys_id of the form view of the record I am on to the map page so that it displays that particular record's coordinates on a map.

Currently, I am overwriting a system property every time the button is clicked with the sys_id of the current record.

I am then pulling out that value and adding it to a query

Is there a better way of doing this? If so what is the best practice? I imagine adding the sys_id to the URL would be a good idea but I'm not sure how best to go about it.

- - - - - - - 
//Set map id system property with sys_id of the current record

var gr = new GlideRecord("sys_properties");
gr.get("sys_id_of_map_id_system_property");
gr.setValue("value", current.sys_id);
gr.update();

// redirect to map

gs.setRedirect("map_page.do?sysparm_sys_id=sys_id_of_map_page");

- - - - - - - 
//Get the sys_id of the record from the map id system property

var myparm = gs.getProperty("map.id");
var gr = new GlideRecord("table");
gr.addQuery('sys_id', myparm);
gr.query();

//add the coordinate sto the map page as a marker

while (gr.next()) {
if (gr.location.latitude && gr.location.longitude) {
var item = map.addItem(gr);
}
7 REPLIES 7

Anil Lande
Kilo Patron

Hi,

Can you please complete script of your UI Action and where you have written 2nd part of script?

Not sure where your UI Action is redirecting and where you need sys_id of record.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Sure thing, I have updated the question with a much longer snippet of the code being used.

The UI Action redirects to the appropriate map page and queries the appropriate table using the value set in the map id system property.

 

I need to find another way to pass this variable without using a system property.

I believe you have a UI Page with name 'map_page.do' and you are calling page from UI Page.

You can pass additional values in URL as parameter like below:

 

gs.setRedirect("map_page.do?sysparm_sys_id=sys_id_of_map_page&record_sys_id="+current.sys_id);

And in UI Page HTML part you can get these parameter values like below:

Use RP.getParameterValue("parameterName")  to read parameter from URL.

 

find_real_file.png

 

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thanks so much for the insightful answer.

In terms of the map page in question, there is unfortunately no UI Page called 'map_page.do'.

Could it be 'gmap' or 'mapping assist'?