Question

Can't filter lookup field according to user role

Hello,

 

I need to display the value "Monthly rate" for user role "Student affairs". So, I added a filter for UsrHousingBookingType Lookup as shown below but nothing is applied.

 

Any help is appreciated!

 

attributes: {
"IsSysAdmin": {
                "dataValueType": this.Terrasoft.DataValueType.BOOLEAN,
                "type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
            },
"UsrBookingTypeCollection": {
                "dataValueType": Terrasoft.DataValueType.COLLECTION,
                "value": Ext.create("Terrasoft.Collection")
            }
},
methods: {
			onEntityInitialized: function() {
                this.callParent(arguments);
				var roleName = "Student Affairs";
				var select = Ext.create("Terrasoft.EntitySchemaQuery", {
					rootSchemaName: "SysUserInRole",
					rowCount: 1
				});
 
                select.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_COLUMN, "Id");
				select.addColumn("SysUser");
				select.addColumn("SysRole");
                var filters = Ext.create("Terrasoft.FilterGroup");
				filters.logicalOperation = Terrasoft.LogicalOperatorType.AND;
			select.filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysUser", Terrasoft.SysValue.CURRENT_USER.value));
				select.filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole", roleName));
select.filters = filters;
 
                select.getEntityCollection(function(result) {
                    if (!result.success || result.collection.getItems().length === 0) {
                        this.set("IsSysAdmin", false); 
                    }
                    else {
                        this.set("IsSysAdmin", true); 
                    }
                }, this);
            },
 
				getBookingTypeValues: function(searchValue, list) {
                var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
                    rootSchemaName:
                    "UsrHousingBookingType"
                });
                esq.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_COLUMN, "value");
                esq.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_DISPLAY_COLUMN, "displayValue");
 
                var positionColumn = esq.addColumn("UsrTestSort");
                positionColumn.orderDirection = Terrasoft.OrderDirection.ASC;
 
                esq.getEntityCollection(function(result) {
                    if (result.success) {
                        list.clear();
                        var preObject = {};
                        result.collection.each(function(item) {
                            if (item.values.displayValue === "Monthly rate"){
                                if (this.get("IsSysAdmin") === true){
                                    preObject[item.get("value")] = item.values;
                                }
                            }
                            else 
                            {
                                preObject[item.get("value")] = item.values;
                            }
                        }, this);
                        list.loadAll(preObject);
                    }
                }, this);
            },
 
	diff: /**SCHEMA_DIFF*/[
{
                "operation": "merge",
                "name": "UsrHousingBookingTypead96e815-e022-4b8b-842f-00aaa7ab3f54",
                "values": {
                    "layout": {
                        "colSpan": 24,
                        "rowSpan": 1,
                        "column": 0,
                        "row": 9
                    }, 
                    "controlConfig": {
                        "list": {
                            "bindTo": "UsrBookingTypeCollection"
                        },
                        "prepareList": {
                            "bindTo": "getBookingTypeValues"
                        }
                    }
                }
            },
]

 

Many thanks,

Mouna.

 

 

Like 0

Like

1 comments

Hi Mouna,

 

ESQ is asynchronous and it won't be able to fit your business task. You need to use the FilterGroup instead to achieve the goal. Here is the community thread with a question similar to your.

 

Best regards,

Oscar 

Show all comments