Hi Everyone,
I need to Hide button based on organizational role. I've used the following code but am not able to achieve the objective.
attributes:{
"IsUserX": {
dataValueType: Terrasoft.DataValueType.BOOLEAN,
type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
value: true
},
},
onEntityInitialized: function() {
// Calling the parent implementation of the onEntityInitialized method.
this.callParent(arguments);
this.fnIsUserX();
},
getSectionActions:function(){
var actionMenuItems = this.callParent(arguments);
actionMenuItems.addItem(this.getButtonMenuItem({
Type:"Terrasoft.MenuSeparator",
Caption:""
}));
//actionMenuItems.addItem(this.getButtonMenuSeparator());
actionMenuItems.addItem(this.getButtonMenuItem({
"Tag":"XYZ",
"Caption":"XYZ",
"Click":{"bindTo":"ABC"},
"Visible": {"bindTo": "IsUserX"},
"Enabled": {"bindTo": "isCustomActionEnabled"},
}));
return actionMenuItems;
},
isCustomActionEnabled: function() {
var selectedRows = this.get("SelectedRows");
console.log(selectedRows);
return selectedRows ? (selectedRows.length > 0 && selectedRows.length <= 50) : false;
},
fnIsUserX:function(){
var currentuser = Terrasoft.SysValue.CURRENT_USER.value;
var esqAdmin = this.Ext.create("Terrasoft.EntitySchemaQuery", {
rootSchemaName: "SysUserInRole"
});
esqAdmin.addColumn("SysRole");
esqAdmin.addColumn("SysUser");
var grpFilters = this.Ext.create("Terrasoft.FilterGroup");
var filterUser = this.Terrasoft.createColumnFilterWithParameter(this.Terrasoft.ComparisonType.EQUAL, "SysUser", currentuser);
var filterRole = this.Terrasoft.createColumnFilterWithParameter(this.Terrasoft.ComparisonType.EQUAL, "SysRole.Name", "XYZ");
grpFilters.addItem(filterUser);
grpFilters.logicalOperation = this.Terrasoft.LogicalOperatorType.AND;
grpFilters.addItem(filterRole);
esqAdmin.filters.add(grpFilters);
esqAdmin.getEntityCollection(function(result) {
if (!result.success) {
this.set("IsUserX",false);
return;
}
else {
var length = result.collection.collection.length;
if (length>0){
this.set("IsUserX", true);
}
}
}, this);
},