Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Hide custom buttons based on the current login user location

chandanpatra
Tera Contributor

Hi All ,

 

Can anyone help me  these four custom buttons should be visible based on the  current login user.

 

For example : only netherland is able to see these buttons in the portal side other than that no one can see these customs buttons :

<button class="select" ng-click="confirm_id()">Confirm UserID</button>
<button class="report" ng-click="report_id()">Report as inappropriate</button>
<button class="select" ng-click="confirm_id()">chandan patra</button>
<button class="select" ng-click="confirm_id()">chandan patra</button>

 

If possible can you provide me HTML, css , server and client script , which i need to write in the widget to achieve this requirements .

 

Thanks and Regards,

Chandan 

3 REPLIES 3

Sid_Takali
Kilo Patron

Hi @chandanpatra Try below code

HTML:

<div ng-if="c.data.showButtons">
    <button class="select" ng-click="confirm_id()">Confirm UserID</button>
    <button class="report" ng-click="report_id()">Report as inappropriate</button>
    <button class="select" ng-click="confirm_id()">chandan patra</button>
    <button class="select" ng-click="confirm_id()">chandan patra</button>
</div>

CSS:

.select {
    background-color: #4CAF50; /* Green */
    color: white;
    border: none;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

.report {
    background-color: #f44336; /* Red */
    color: white;
    border: none;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

Client Script:

(function() {
    var userLocation = $scope.data.userLocation;


    $scope.data.showButtons = (userLocation === 'Netherlands');

    $scope.confirm_id = function() {
        alert('Confirm UserID clicked');
    };

    $scope.report_id = function() {
        alert('Report as inappropriate clicked');
    };
})();

Server Script :

(function() {
  
    var userGr = new GlideRecord('sys_user');
    userGr.get(gs.getUserID());

    // Replace `location` with the actual field name that stores the user's location
    var userLocation = userGr.location.name;

    data.userLocation = userLocation;
})();

 

 

Sorry from my side client script is not working properly , i have one extra requirement in the A button should visible india , asia and malasia user. b button should visible netherland , c button should visible austilla user and d  button should visible  china user .

 

Can you modify this code and client script is not working 

 

Thanks ,

Chandan 

@Sid_Takali  : Thank you from my side 

In the above script " c.ddata.showbuttons" it is not working  , can you replace this code .

 

Thanks ,

Chandan