Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

Hide UI Action button based on field value on Load after saving.

VullankiL
Tera Contributor

There is a ui action button Input Required (input_required) with some other conditions that needed. hence, they used onclick functions in script field.
Now my requirement is that I am using these Input Required button in change_request table.

It has one field requested_by (reference field). 
if the user in the requested_by field is part of Software Group, then i want to hide the input_required button. It have to work when "onLoad" not onChange. 
How can I achieve this using client script or Script include or both. what is the answer? 
Please help me with this.

6 REPLIES 6

Mark Manders
Tera Patron

It's a ui action, so just use the condition field: !gs.getUser().isMemberOf('Software')

But here i want to check the user in requested_by field is part of Software group.
Not the current user. 

How can i achieve this?

Use this in the condition:

new UserGroupChecker().isRequestedByInGroup(current.sys_id, 'Software') == false

 

with this script include:

var UserGroupChecker = Class.create();
UserGroupChecker.prototype = {
    initialize: function() {
    },

    isRequestedByInGroup: function(changeRequestId, groupName) {
        var changeRequest = new GlideRecord('change_request');
        if (changeRequest.get(changeRequestId)) {
            var requestedBy = changeRequest.requested_by;
            if (!requestedBy.nil()) {
                var userGR = new GlideRecord('sys_user');
                if (userGR.get(requestedBy)) {
                    var user = new GlideUser(userGR.sys_id);
                    return user.isMemberOf(groupName);
                }
            }
        }
        return false;
    },

    type: 'UserGroupChecker'
};

Still the input required button is not hiding. Please find the attachements and let me know if there is any changes.