Hide widget for a group

Poorva Bhawsar
Mega Sage

Hi Community,

 

How to hide a service portal widget for a group.

 

I need help in the logic.

 

Thanks,

Poorva Bhawsar

9 REPLIES 9

Community Alums
Not applicable

Hi @Poorva Bhawsar ,

Assign user criteria to pages, widgets, or widget instances to limit user access to content in a portal.

Before you begin

Activate the Service Portal User Criteria Support (com.glide.service-portal.user-criteria) plugin and set the glide.service_portal.user_criteria_enabled system property to true.

Role required: admin or sp_admin

About this task

You can apply several user criteria records to a single portal item.

Procedure

  1. In the Service Portal Configuration page (Service Portal > Service Portal Configuration), open the Page Editor.
  2. Select a page from the list.
  3. Select a page, widget, or widget instance node from the page tree.
  4. Under related lists, click Who Can View or Who Cannot View.
  5. Click New.
  6. Select a criteria from the Can View or Cannot View list.

    Selecting criteria from the Can View or Cannot View list applies user criteria records created in Create a user criteria record for Service Portal to the selected page, widget, or widget instance.

  7. Click Save.

 

Here i want to hide a reopen widget when an incident is assigned to xyz group.

Gopal Allu
Tera Expert

Hi @Poorva Bhawsar ,

 

In server script you can give like if logged in user is member of that respective group. You can hide that widget using the flag passing as true or false to html code.

Html:

<div ng-if=data.showwid>

//your widget code

</div>

 

Server script:

var wid = gs.getUser().isMemberOf("your group name");

if(wid == true)

data.showwid = false;

else

data.showwid = true;

 

Please mark it correct. If it is helpful.

 

Thanks and Regards,

Allu Gopal.

 

 

Can you help me that i am adding the code at correct place or not?

 

Here is the HTML part.

 

<div>
<div class="dropdown" id="child-case-tabs" ng-if="data.showActions">
<button type="button" id="actions-button" class="btn btn-default dropdown-toggle action-btn" data-toggle="dropdown" style="width : 100%" aria-haspopup="true" ng-init="setFocusOnActionButtons()">
${Actions}
<span class="fa fa-caret-down"></span>
</button>
<ul class="dropdown-menu pull-right" id="actionList">
<li ng-if="data.canResolve">
<a href="javascript&colon;void(0)" ng-click="$event.stopPropagation();resolveIncident()">${Resolve}</a>
</li>
<div ng-if=data.showwid>
<li ng-if="data.canReopen">
<a href="javascript&colon;void(0)" ng-click="$event.stopPropagation();reopenIncident()">${Reopen}</a>
</li>
</div>
<li ng-if="data.canClose">
<a href="javascript&colon;void(0)" ng-click="$event.stopPropagation();closeIncident()">${Close}</a>
</li>
</ul>
</div>

</div>

 

Here is the server script.

 

(function() {
    if (!new global.SNCACLWidgetUtil().hasPublicAccess('9bd06ce173070010cbb654eb7df6a7d4', $sp.getParameter('table'))) {
        return;
    }
    var incidentGr = new GlideRecord('incident');
    var incidentSysId = options.sys_id;

    if (!incidentSysId && $sp.getParameter('table') == 'incident')
        incidentSysId = $sp.getParameter('sys_id');

    if (!incidentSysId && $sp.getParameter('table') == 'universal_request') {
        var urGr = new GlideRecord('universal_request');
        urGr.get($sp.getParameter('sys_id'));
        incidentSysId = urGr.primary_task + '';
    }

    var secureCheck = new GlideRecord('incident');
    var canEdit = secureCheck.get(incidentSysId) && (secureCheck.canWrite() || secureCheck.getValue('caller_id') == gs.getUserID() || secureCheck.getValue('opened_by') == gs.getUserID());
    if (!canEdit) {
        return;
    }

    /* Actions - Start */
    if (input && input.action == 'resolveIncident' && incidentGr.get(incidentSysId)) {
        incidentGr.incident_state = global.IncidentState.RESOLVED;
        incidentGr.state = global.IncidentState.RESOLVED;
        incidentGr.resolved_by = gs.getUserID();
        data.isIncidentResolved = incidentGr.update();
    }

    if (input && input.action == 'reopenIncident' && incidentGr.get(incidentSysId)) {
        incidentGr.incident_state = global.IncidentState.IN_PROGRESS;
        incidentGr.state = global.IncidentState.IN_PROGRESS;
        incidentGr.comments = "Reason for rejection: " + input.rejectReason; //Line added for fixing INC3257360
        data.isIncidentReopened = incidentGr.update();
        gs.addInfoMessage(gs.getMessage("Request reopened"));
    }

    if (input && input.action == 'closeIncident' && incidentGr.get(incidentSysId)) {
        incidentGr.incident_state = global.IncidentState.CLOSED;
        incidentGr.state = global.IncidentState.CLOSED;
        data.isIncidentClosed = incidentGr.update();
    }

    /* Actions - End */

    /* Load incident data */
    if (incidentGr.get(incidentSysId)) {
        var incidentUtils = new global.IncidentUtils();
        data.canResolve = incidentUtils.canResolveIncident(incidentGr);
        /**START - Change to fix INC3257360**/
        if (incidentGr.state == 6) {
            data.canReopen = true;
        }
        //data.canReopen = incidentUtils.canReopenIncident(incidentGr);
        /**END - Change to fix INC3257360**/
        data.canClose = incidentUtils.canCloseIncident(incidentGr);
        data.showActions = data.canResolve || data.canReopen || data.canClose;
    }

    data.i18n = {};

    var wid = gs.getUser().isMemberOf("Command Centre");
    if (wid == true)
        data.showwid = false;
    else
        data.showwid = true;

})();