How to add hyper link to incident record in service portal?

sri83
Tera Guru

Hi Team,

 

I have created the widget to show all the priority 1 incidents on the form. But i don't have an idea how to add the hyperlink and edit option access to the incident. I would appreciate your assistance in adding it to the script.

 

HTML Template Script:

 

<div class="panel panel-default">
<div class="panel-heading">${Most Current Priority 1 Tickets}
<div class="panel-body">
<table class="table table-bordered">
<tr>
<th>Incident Number</th>
<th>Short Description</th>
<th>Description</th>
<th> Edit Record</th>
</tr>
<tr ng-repeat ="temp in data.incidentList">
<td>{{temp.number}}</td>
<td> {{temp.short_description}} </td>
<td> {{temp.description}} </td>
<td><button type="button" data-toggle="tooltip" title="Edit"><i class="fa fa-edit"></i></button></td>
</tr>
</table>
<div class="primary-display">
<a href="?id={{::item.url.id}}&table={{::item.url.table}}&sys_id={{::item.url.sys_id}}" sn-focus="{{::item.highlight}}" aria-label="{{::item.display_field}} , {{::item.display_number}}"> {{::item.number}} </a>
</div>
<input type="submit" value="update" class="btn btn-primary" ng-click ='c.update(temp1)'>
</div>
</div>

 

Client Script:

 

api.controller=function() {
/* widget controller */
var c = this;
c.updateRecord=function(temp1){
c.data.short_description =temp1.short_description;
c.data.description =temp1.description;
c.server.update().then(function(){
c.data={};
});
}
}

 

Server Side Script:

 

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */

var incRec = new GlideRecord('incident');
incRec.addQuery('active', true);
incRec.addQuery('priority', 1);
incRec.orderByDesc('sys_created_on');
incRec.setLimit(5);
incRec.query();
data.incidentList = [];

while (incRec.next()) {
var temp = {};
temp.number = incRec.number.toString();
temp.short_description = incRec.short_description.toString();
temp.description = incRec.description.toString();
data.incidentList.push(temp);
//gs.addInfoMessage("get the table data"+data.incidentList[0].number);
}

})();

if(input){
gs.addInfoMessage("getDatails:"+input.short_description);
}

var incupdate =new GlideRecord('incident');
incupdate.addQuery('active', true);
incupdate.addQuery('priority', 1);
while(incupdate.next()){
incupdate.short_description = input.short_description;
incupdate.description = input.description;
incupdate.update();
}

 

 

3 REPLIES 3

Mike_R
Kilo Patron
Kilo Patron

Try this. It will make the Incident number a hyperlink

HTML

 

 

<div class="panel panel-default">
<div class="panel-heading">${Most Current Priority 1 Tickets}
<div class="panel-body">
<table class="table table-bordered">
<tr>
<th>Incident Number</th>
<th>Short Description</th>
<th>Description</th>
<th> Edit Record</th>
</tr>
<tr ng-repeat ="temp in data.incidentList">
<td><a href="/sp?id=form&table=incident&sys_id={{temp.sys_id}}">{{temp.number}}</a></td>
<td> {{temp.short_description}} </td>
<td> {{temp.description}} </td>
<td><a href="/sp?id=form&table=incident&sys_id={{temp.sys_id}}"><button type="button" data-toggle="tooltip" title="Edit"><i class="fa fa-edit"></i></button></td></a>
</tr>
</table>
<div class="primary-display">
<a href="?id={{::item.url.id}}&table={{::item.url.table}}&sys_id={{::item.url.sys_id}}" sn-focus="{{::item.highlight}}" aria-label="{{::item.display_field}} , {{::item.display_number}}"> {{::item.number}} </a>
</div>
</div>
</div>

 

 

 

 

Client 

 

 

api.controller=function() {
/* widget controller */
var c = this;
c.updateRecord=function(temp1){
c.data.short_description =temp1.short_description;
c.data.description =temp1.description;
c.server.update().then(function(){
c.data={};
});
}
}

 

 

 

 

Server

 

 

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */

var incRec = new GlideRecord('incident');
incRec.addQuery('active', true);
incRec.addQuery('priority', 1);
incRec.orderByDesc('sys_created_on');
incRec.setLimit(5);
incRec.query();
data.incidentList = [];

while (incRec.next()) {
var temp = {};
temp.number = incRec.number.toString();
temp.short_description = incRec.short_description.toString();
temp.description = incRec.description.toString();
temp.sys_id = incRec.sys_id.toString();
data.incidentList.push(temp);
//gs.addInfoMessage("get the table data"+data.incidentList[0].number);
}

})();

if(input){
gs.addInfoMessage("getDatails:"+input.short_description);
}

var incupdate =new GlideRecord('incident');
incupdate.addQuery('active', true);
incupdate.addQuery('priority', 1);
while(incupdate.next()){
incupdate.short_description = input.short_description;
incupdate.description = input.description;
incupdate.update();
}

 

 

Thanks Mike for reply.

 

I have added the suggested HTML data it's redirecting to the new incident form. I want to open the same incident which the details on the portal form.

When the click the link it's showing as you don't have access......

 

 

<div class="panel panel-default">
<div class="panel-heading">${Most Current Priority 1 Tickets}
<div class="panel-body">
<table class="table table-bordered">
<tr>
<th>Incident Number</th>
<th>Short Description</th>
<th>Description</th>
<th> Edit Record</th>
</tr>
<tr ng-repeat ="temp in data.incidentList">
<td><a href="/sp?id=ticket&table=incident&sys_id={{temp.sys_id}}">{{temp.number}}</a></td>
<td> {{temp.short_description}} </td>
<td> {{temp.description}} </td>
<td><a href="/sp?id=form&table=incident&sys_id={{temp.sys_id}}"><button type="button" data-toggle="tooltip" title="Edit"><i class="fa fa-edit"></i></button></a></td>
</tr>
</table>
<div class="primary-display">
<a href="?id={{::item.url.id}}&table={{::item.url.table}}&sys_id={{::item.url.sys_id}}" sn-focus="{{::item.highlight}}" aria-label="{{::item.display_field}} , {{::item.display_number}}"> {{::item.number}} </a>
</div>
</div>
</div>

 

sri83_0-1666762911068.png

 

 

 

 

 

 

Make sure you copy the Server Script I provided too.

 

Copy all the code i provided, test it out, and then tweak as needed. The code is working for me.