- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 02:49 AM
When a user logs in and if the record exists in u_employee_sv table, then the Open Record button must be visible.
If the record does not exist, then the Report Missing Record button must be visible.
Widget in the service portal:
HTML for the buttons:
<button class="button-31" id="open-button" ng-click="c.openRecord(data.sys_id);">
Open Record
</button>
<br>
<button class="button-31" id="report-button" ng-click="c.report();">
Report Missing Record
</button>
Client Script:
api.controller=function() {
/* widget controller */
var c = this;
c.openRecord = function(id){
var url="?id=form&table=u_employee_sv&sys_id="+id;
window.open(url,'_blank');
}
};
Server Script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var employeeGR = new GlideRecord("u_employee_sv");
employeeGR.addQuery('u_reference_1', gs.getUserID());
employeeGR.query();
//gs.addInfoMessage("ID: "+employeeGR.getRowCount());
if(employeeGR.next()){
data.empID = employeeGR.u_number.toString();
data.name = employeeGR.u_reference_1.name.toString();
data.email = employeeGR.u_reference_1.email.toString();
data.department = employeeGR.u_department.name.toString();
data.manager = employeeGR.u_reference_1.manager.name.toString();
data.sys_id = employeeGR.getValue('sys_id');
//data.description = employeeGR.u_employee_self_description.toString();
} else {
}
})();
How do I do this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 04:06 AM
Here is the fix.
HTML for the buttons:
<div>
<button class="button-31" id="open-button" ng-click="c.openRecord(data.sys_id);" ng-if="data.showOpen">
Open Record
</button>
<br>
<button class="button-31" id="report-button" ng-click="c.report();" ng-if="data.showMissing">
Report Missing Record
</button>
</div>
Client Script: No change in client script
Server side script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var employeeGR = new GlideRecord("u_employee_sv");
employeeGR.addQuery('u_reference_1', gs.getUserID());
employeeGR.query();
//gs.addInfoMessage("ID: "+employeeGR.getRowCount());
if(employeeGR.next()){
data.empID = employeeGR.u_number.toString();
data.name = employeeGR.u_reference_1.name.toString();
data.email = employeeGR.u_reference_1.email.toString();
data.department = employeeGR.u_department.name.toString();
data.manager = employeeGR.u_reference_1.manager.name.toString();
data.sys_id = employeeGR.getValue('sys_id');
//data.description = employeeGR.u_employee_self_description.toString();
data.showOpen=true;
data.showMissing = false;
} else {
data.showOpen=false;
data.showMissing = true;
}
})();
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 04:06 AM
Here is the fix.
HTML for the buttons:
<div>
<button class="button-31" id="open-button" ng-click="c.openRecord(data.sys_id);" ng-if="data.showOpen">
Open Record
</button>
<br>
<button class="button-31" id="report-button" ng-click="c.report();" ng-if="data.showMissing">
Report Missing Record
</button>
</div>
Client Script: No change in client script
Server side script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var employeeGR = new GlideRecord("u_employee_sv");
employeeGR.addQuery('u_reference_1', gs.getUserID());
employeeGR.query();
//gs.addInfoMessage("ID: "+employeeGR.getRowCount());
if(employeeGR.next()){
data.empID = employeeGR.u_number.toString();
data.name = employeeGR.u_reference_1.name.toString();
data.email = employeeGR.u_reference_1.email.toString();
data.department = employeeGR.u_department.name.toString();
data.manager = employeeGR.u_reference_1.manager.name.toString();
data.sys_id = employeeGR.getValue('sys_id');
//data.description = employeeGR.u_employee_self_description.toString();
data.showOpen=true;
data.showMissing = false;
} else {
data.showOpen=false;
data.showMissing = true;
}
})();
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 04:59 AM
Thank you. It worked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2023 07:10 AM
Glad it helped.