Question

Convert esq.getEntityCollection to list of lookup values (Terrasoft.DataValueType.LOOKUP)

Hi,

I have a field on a detail that I want to filter by another lookup on a different detail. 

(There is a detail: school in project on the project page. Users can pick multiple schools. Inside another detail on the project page, Project event detail, I have another detail called school in Project Event. I want to school lookup to only show values that were picked by the first detail, school in project.

I set an attribute and create function to get the list of schools via esq.

I don't know how to convert the schools list to a list I can use to return on the filter of the attribute.

		attributes: {
 
			 "UsrSchool": {
                dataValueType: this.Terrasoft.DataValueType.LOOKUP,
                "lookupListConfig": {
                    "filters": [
                        function() {
							console.log("att of school filter got here!");
							var schoolsList;
                            	var EventId = this.get("MasterRecordId");
				if (EventId) {
					var esq = Ext.create("Terrasoft.EntitySchemaQuery",{
						rootSchemaName: "UsrUsrSchoolInProject",
					});
					//project
					esq.addColumn("UsrLookup1");
					//school
					esq.addColumn("UsrLookup2");
					var esqFilter = Terrasoft.createColumnFilterWithParameter(
						this.Terrasoft.ComparisonType.EQUAL,"UsrLookup1",EventId);
					esq.filters.add(esqFilter);
					esq.getEntityCollection(function(result){
						result.collection.each(function (item) {
                // setting received account from detail to a variable
							var account = item.get("UsrLookup2").value;
							console.log("school 1 - ",account);
							schoolsList.Add(account);
						});
						return schoolsList;
					});
 
				}
                        }
                    ]
                }

 diff: /**SCHEMA_DIFF*/[

				"operation": "insert",
				"name": "UsrSchool52cebb58-4d96-4c3b-8737-2474daf56728",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 0,
						"row": 1,
						"layoutName": "Header"
					},
					"bindTo": "UsrSchool"
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 1
			}

 

Thanks in advance,

Chani

Like 0

Like

3 comments

Hi Chani,

 

Most probably the issue is that ESQ is async so that's why you get empty shoolList in the dropdown of the lookup and only then ESQ itself is executed. Please use a regular approach with filterGroup as described here for example. 

Oleg Drobina,

Thank you. 

How would I use the filterGroup with results from another object? I can't just use basic filters as I need to get a different object and check the data here.

For example: 

Project X has 3 schools associated with, by the detail 'school in project', schools a, b, and c. 
Project X has the detail 'events in project'. The events in project object has a detail called 'school in event'. 

I need the school lookup of the school in event detail of all events on project X to only display schools a, b, and c.

Chani Karel,

Anyone?

Show all comments