- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 04:21 AM
Hello ,
I am trying to make a variable in the Server Script to get sys_id and name from a table and then write in HTML a line that displays that information. Can someone help me ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 05:28 AM
Hi,
In following example I am showing first 10 records of incident table in service portal
Server script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.table = {
"list" : []
};
var count = 0;
var gr = new GlideRecord("incident");
gr.addEncodedQuery('active=true');
gr.orderBy('number');
gr.setLimit(10);
gr.query();
while(gr.next()){
count++;
var obj = {};
obj.id = count;
obj.number = gr.getValue('number');
obj.short_description = gr.getValue('short_description');
obj.assign_to = gr.getDisplayValue('assigned_to');
data.table.list.push(obj);
}
})();
Html script:
<div>
<h2>
INCIDENT LIST
</h2>
<table class = "table-striped" style="width: 100%;">
<tr>
<th>Id</th>
<th>Number</th>
<th>Short Description</th>
<th>Assigned To</th>
</tr>
<tr ng-repeat="row in c.data.table.list">
<td>
{{row.id}}
</td>
<td>
{{row.number}}
</td>
<td>
{{row.short_description}}
</td>
<td>
{{row.assign_to}}
</td></tr>
</table>
</div>
css script:
table, tr,td{
border-collapse: collapse;
border: 1px solid black;
padding: 20px;
//width: 100%;
}
}
th{
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
color: white;
background-color: #04AA6D;
}
h2{
text-align: center;
}
Output:
INCIDENT LIST
Id | Number | Short Description | Assigned To |
---|---|---|---|
1 | INC0000001 | This is short description from another instance | Mid Server |
2 | INC0000003 | Wireless access is down in my area | Beth Anglin |
3 | INC0000007 | Need access to sales DB for the West | David Loo |
4 | INC0000015 | I can't launch my VPN client since the last software update | Don Goodliffe |
5 | INC0000016 | Rain is leaking on main DNS Server | ITIL User |
6 | INC0000017 | How do I create a sub-folder | Fred Luddy |
7 | INC0000018 | Sales forecast spreadsheet is READ ONLY | ITIL User |
8 | INC0000019 | Can't launch 64-bit Windows 7 virtual machine | Bud Richman |
9 | INC0000020 | I need a replacement iPhone, please | ITIL User |
10 | INC0000025 | Need to add more memory to laptop | ITIL User |
Please mark correct/helpful based on an impact.
Regards,
Aniket sawant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 05:28 AM
Hi,
In following example I am showing first 10 records of incident table in service portal
Server script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.table = {
"list" : []
};
var count = 0;
var gr = new GlideRecord("incident");
gr.addEncodedQuery('active=true');
gr.orderBy('number');
gr.setLimit(10);
gr.query();
while(gr.next()){
count++;
var obj = {};
obj.id = count;
obj.number = gr.getValue('number');
obj.short_description = gr.getValue('short_description');
obj.assign_to = gr.getDisplayValue('assigned_to');
data.table.list.push(obj);
}
})();
Html script:
<div>
<h2>
INCIDENT LIST
</h2>
<table class = "table-striped" style="width: 100%;">
<tr>
<th>Id</th>
<th>Number</th>
<th>Short Description</th>
<th>Assigned To</th>
</tr>
<tr ng-repeat="row in c.data.table.list">
<td>
{{row.id}}
</td>
<td>
{{row.number}}
</td>
<td>
{{row.short_description}}
</td>
<td>
{{row.assign_to}}
</td></tr>
</table>
</div>
css script:
table, tr,td{
border-collapse: collapse;
border: 1px solid black;
padding: 20px;
//width: 100%;
}
}
th{
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
color: white;
background-color: #04AA6D;
}
h2{
text-align: center;
}
Output:
INCIDENT LIST
Id | Number | Short Description | Assigned To |
---|---|---|---|
1 | INC0000001 | This is short description from another instance | Mid Server |
2 | INC0000003 | Wireless access is down in my area | Beth Anglin |
3 | INC0000007 | Need access to sales DB for the West | David Loo |
4 | INC0000015 | I can't launch my VPN client since the last software update | Don Goodliffe |
5 | INC0000016 | Rain is leaking on main DNS Server | ITIL User |
6 | INC0000017 | How do I create a sub-folder | Fred Luddy |
7 | INC0000018 | Sales forecast spreadsheet is READ ONLY | ITIL User |
8 | INC0000019 | Can't launch 64-bit Windows 7 virtual machine | Bud Richman |
9 | INC0000020 | I need a replacement iPhone, please | ITIL User |
10 | INC0000025 | Need to add more memory to laptop | ITIL User |
Please mark correct/helpful based on an impact.
Regards,
Aniket sawant