how to get list of records in a link

Priti18
Tera Expert

list =[sys ids of records];

var tablerec = '<table><thead><tr><th>Incident Number</th></tr></thead><tbody>';
var baseURL = gs.getProperty('glide.servlet.uri');
for (var i = 0; i < list.length; i++) {
var url = new GlideURL('incident.do');
url.addParam('sys_id', list[i]);
var link = baseURL + url.getURL();
tablerec += '<tr><td><a href="' + incidentLink + '">' + list[i] + '</a></td></tr>';
}
tablerec += '</tbody></table>';

 

am 

1 ACCEPTED SOLUTION

Hi Priti,

 

Thats because yoru list array contains the sys_ids and not the numbers.

list =[numbers seprated by commas];

var tablerec = '<table><thead><tr><th>Incident Number</th></tr></thead><tbody>';
var baseURL = gs.getProperty('glide.servlet.uri');
var gr = new GlideRecord("incident");
gr.addEncodedQuery("numberIN"+list);
gr.query();
while(gr.next()) {
 var url= '<a href="' + gs.generateURL(gr.getTableName(),gr.sys_id) +  '">' + gr.number+ '</a>';
tablerec += '<tr><td>'+url+'</td></tr>';
}
tablerec += '</tbody></table>';

 

View solution in original post

4 REPLIES 4

asifnoor
Kilo Patron

Hello Priti,

 

1. Glideurl is a client side object. you cannot use it in server side

2. if you want to fetch the url, then you can modify the code slightly like this

list =[sys ids of records];

var tablerec = '<table><thead><tr><th>Incident Number</th></tr></thead><tbody>';
var baseURL = gs.getProperty('glide.servlet.uri');
for (var i = 0; i < list.length; i++) {
var url = "incident.do?sys_id="+list[i]+"";
var link = baseURL + url;
tablerec += '<tr><td><a href="' + incidentLink + '">' + list[i] + '</a></td></tr>';
}
tablerec += '</tbody></table>';

 

Mark the comment as a correct answer and helpful if this helps to solve the problem.

I am able to get link of records but the hyperlink shows as the sys id of those records i need numbers.

Hi Priti,

 

Thats because yoru list array contains the sys_ids and not the numbers.

list =[numbers seprated by commas];

var tablerec = '<table><thead><tr><th>Incident Number</th></tr></thead><tbody>';
var baseURL = gs.getProperty('glide.servlet.uri');
var gr = new GlideRecord("incident");
gr.addEncodedQuery("numberIN"+list);
gr.query();
while(gr.next()) {
 var url= '<a href="' + gs.generateURL(gr.getTableName(),gr.sys_id) +  '">' + gr.number+ '</a>';
tablerec += '<tr><td>'+url+'</td></tr>';
}
tablerec += '</tbody></table>';

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Priti18 

can you share your complete business requirement here?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader