- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2019 11:28 AM
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;
}
})();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2019 12:10 PM
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.
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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2019 12:10 PM
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.
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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2019 12:47 PM
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 😉