Hide widget for incident record in serviceportal

rmishra4395
Tera Contributor

Hello Everyone,

 

Greetings!

I have created a widget which will show approval details to end users that with whom the approval is pending, it will show the approver name.

 

It is working perfectly fine but this widget is showing for incident record also, i want to hide this widget for incident record.

 

Please find my below script for refernce.

 

HTML:

 

<div ng-if="!c.data.hideWidget">
<div ng-if="!c.data.appDetails.length">
No Approvals
</div>
<table class="table table-striped table-responsive" ng-if="c.data.appDetails.length">
<thead>
<tr style="border-radius:6px;">
<th>${Approvers}</th>
<th>${Group}</th>
<th>${State}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in data.appDetails" style="border-radius:6px;">
<td>{{::item.name}}</td>
<td>{{::item.group}}</td>
<td>{{::item.state}}</td>
</tr>
</tbody>
</table>
</div>

 

 

Server Script:

 

(function() {
    data.appDetails = [];
    var sysId = $sp.getParameter("sys_id");
    var table = $sp.getParameter("table");

    // Check if the table is incident
    if (table === 'incident') {
        data.hideWidget = true;
        return;
    } else {
        data.hideWidget = false;
    }

    gs.log(sysId);
    var query = "document_id=" + sysId;
    var approvals = new GlideRecord("sysapproval_approver");
    approvals.addEncodedQuery(query);
    approvals.addQuery('state', 'approved').addOrCondition('state', 'requested');
    approvals.sortByDesc('sys_created_on');
    approvals.query();
    while (approvals.next()) {
        var obj = {};
        obj.name = approvals.getDisplayValue('approver');
        obj.group = approvals.getDisplayValue('group.assignment_group'); // Dot-walking to fetch group
        obj.state = approvals.getDisplayValue('state');
        obj.created = approvals.getDisplayValue('sys_created_on');
        data.appDetails.push(obj);
    }
})();
 
 
 
Please help me with the solution!
1 REPLY 1

AnirudhKumar
Mega Sage
Mega Sage

Change line 1 from:

 

<div ng-if="!c.data.hideWidget">

 

 to:

 

<div ng-if="data.hideWidget == true">

 

 

Also, I see you have gs.log() in your code.

Switch to gs.info(). log statements do not work in scoped apps.

Whereas info statements can be used in both global and scoped apps.

 

Edit: my original condition was incorrect, use this one please:

<div ng-if="data.hideWidget == false">