How do I Create a Dynamic Hyperlink on an Icon Link to Refer to a Specific Record?

Jordan Humphre1
Giga Contributor

I am looking to create an icon link on a Service Portal page that takes the sys_id of the record being presented, and generate a URL like this: "core_company.do?sys_id={{data.sysid}}" where the token is replaced with the sys_id of the record currently being viewed.

My question is, how can one do this with minimal coding? I want to also only display this to users with write access to the core_company table.

Here's my code:

 

Server: 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	
	//Get the sysid passed from URL of the record:
	var sysvalue = $sp.getParameter('sys_id');
	
	var gr = new GlideRecord('core_company');
	//var user_sys;
	if (gr.get(sysvalue)){
		data.name = gr.name.toString();
		data.phone = gr.phone.toString();
		data.fax = gr.fax_phone.toString();
		data.email = gr.email.toString();
		data.acct = gr.u_vendoracct.toString();		
		data.notes = gr.notes.toString();
		data.venmgr = gr.vendor_manager.getDisplayValue();
		data.sysid = sysvalue;
		}
})();

 

1 ACCEPTED SOLUTION

reginabautista
Kilo Sage

Hi, there is an OOTB code that does something similar. It's better as it opens the current record in the native UI.

 

Try to do the following:

1. https://<yourinstance>.service-now.com/sp?id=form&table=incident&sys_id=ed92e8d173d023002728660c4cf6a7bc (change sys_id to the sys_id of any records in your incident table

 

2. The incident will open on the Form widget. Click on the Open in platform to see the behaviour.

find_real_file.png

 

3. You could apply similar functionality for your purposes by opening the widget in Editor (Press and hold Ctrl key + Right click anywhere on the form + Choose in Widget Editor

The HTML code should be something like this:

 <li ng-if="::data.isAdmin"><a ng-href="/{{::data.f.table}}.do?sys_id={{data.f.sys_id}}&sysparm_view={{data.f.view}}" target="_blank">${Open in platform}</a></li>

View solution in original post

2 REPLIES 2

reginabautista
Kilo Sage

Hi, there is an OOTB code that does something similar. It's better as it opens the current record in the native UI.

 

Try to do the following:

1. https://<yourinstance>.service-now.com/sp?id=form&table=incident&sys_id=ed92e8d173d023002728660c4cf6a7bc (change sys_id to the sys_id of any records in your incident table

 

2. The incident will open on the Form widget. Click on the Open in platform to see the behaviour.

find_real_file.png

 

3. You could apply similar functionality for your purposes by opening the widget in Editor (Press and hold Ctrl key + Right click anywhere on the form + Choose in Widget Editor

The HTML code should be something like this:

 <li ng-if="::data.isAdmin"><a ng-href="/{{::data.f.table}}.do?sys_id={{data.f.sys_id}}&sysparm_view={{data.f.view}}" target="_blank">${Open in platform}</a></li>

ASA5
Kilo Sage

Hi,

You can clone the icon link widget, and change the server script to : 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	
	//Get the sysid passed from URL of the record:
	var sysvalue = $sp.getParameter('sys_id');
	
	var grCompany = new GlideRecord('core_company');
	//var user_sys;
	if (grCompany.get(sysvalue)){
		data.name = grCompany.name.toString();
		data.phone = grCompany.phone.toString();
		data.fax = grCompany.fax_phone.toString();
		data.email = grCompany.email.toString();
		data.acct = grCompany.u_vendoracct.toString();		
		data.notes = grCompany.notes.toString();
		data.venmgr = grCompany.vendor_manager.getDisplayValue();
		data.sysid = sysvalue;
	}

       var gr = $sp.getInstanceRecord();

	data.href = $sp.getMenuHREF(grCompany);
	data.target = options.target || "";

       data.canWrite = grCompany.canWrite();
})();

 

For the HTML part you can add ng-if="c.data.canWrite" to the first div 😉