How to filtering lookup with static filter that i have 1 object that is relation to contact and account, and i want to filter if the account is has been added to the object then the account not display in the lookup

Like 2

Like

1 comments

The necessary filtering can be implemented in section page source code. In order to do that you will have to write the handler for crt.LoadDataRequest request that appears when the lookup is opened.

Here is the example of the implementation:
 

/**SCHEMA_MODEL_CONFIG_DIFF*/,
	handlers: /**SCHEMA_HANDLERS*/[
		{
			request: "crt.LoadDataRequest",
			handler: async (request, next) => { 
				if(request.dataSourceName !== "PDS_UsrDoctor_sm2qg7w_List_DS") {
					return await next?.handle(request);
				}
				console.log('Lookup Load Data...');
				const cardModel = await sdk.Model.create("UsrHospitalVisitCardV3");
 
				// now load the records and provide the filters             
				const cards = await cardModel.load({
					attributes: ["UsrDoctor"]
				});
				console.log(cards);
 
				if (cards) {
					const filter = new sdk.FilterGroup();
					filter.logicalOperation = sdk.LogicalOperatorType.Or;
					cards.forEach(async (card) => {
						if(card.UsrDoctor && card.UsrDoctor.value){
							await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Id", card.UsrDoctor.value);
						}
					});
 
					// note, these lines are only needed due to an issue with filters in Creatio-DevKit SDK
					// expected to be fixed in Creatio 8.1
					const newFilter = Object.assign({}, filter);
					newFilter.items = filter.items;
 
					request.parameters.push({
						type: "filter",
						value: newFilter
					});
				}
 
				return await next?.handle(request);
			}
		}
	]/**SCHEMA_HANDLERS*/

 
In the example above "PDS_UsrDoctor_sm2qg7w_List_DS" is the name of the lookup that has to be filtered and "UsrHospitalVisitCardV3" is the object that contains that lookup and which records we should check.

You can also find some additional details and useful information in the articles:
https://customerfx.com/article/dynamically-filtering-a-lookup-on-a-creatio-freedom-ui-page/
https://customerfx.com/article/querying-data-using-filter-conditions-via-the-model-class-equivalent-to-enityschemaquery-in-a-creatio-freedom-ui-page/

Show all comments

Hello,

I have a section called Applications which has an Owner field that points to contact lookup. The application section also has a field that points to Company Lookup. I also have a Company section. Inside this section there is a detail called Workers to which contacts are added.

 

I want to filter Owner lookup to show contacts who are added to the Workers detail of the company which is mapped to the Application. Please see below image. Can someone help with the lookup filter?

 

Like 0

Like

3 comments
Best reply

Shivani Lakshman,

 

Change the filter from "[UsrWorkers.UsrWorker].UsrAccount.Id" to "[UsrWorkers:UsrWorker].UsrAccount.Id"

 

My bad, I forgot that in reverse join it work using ":", for example :

[EntityCode:FieldCode]

 

and not [EntityCode.FieldCode]

 

regards,

 

Julien

Hi Shivani,

 

To filter your lookup you need to add this attribute in the application page :

attributes: {
    "Owner": {
        "dataValueType": Terrasoft.DataValueType.LOOKUP,
        "lookupListConfig": {
            "filters": [function() {
                var filters = Ext.create("Terrasoft.FilterGroup");
                filters.add("WorkInThisCompany", 
                    Terrasoft.createColumnFilterWithParameter(
                        Terrasoft.ComparisonType.EQUAL,
                        "[Workers:Worker].Company.Id",
                        this.get("Company").value
                    )
                );
                return filters;
            }]
        }
    }
}

Replace "Workers" by the object code of the workers detail.

 

FYI :

here is the filter breakdown :

"[WorkerObjectCode:WorkerFieldCodeInWorkers].CompanyFieldInWorkers.Id"

 

Watch out that all the codes correspond to your environment, for example, the workers object code can be "UsrWorkers" or whatever you defined it. Check it out in the advanced settings.

 

Kind regards,

 

Julien

Julien Gunther,

Thank you for your response. I tried your code but received the error 

Collection item with name [UsrWorkers not found.

 

 request data: {"rootSchemaName":"Contact","operationType":0,"includeProcessExecutionData":true,"filters":{"items":{"searchFilter":{"items":{"1f59bb71-8f5d-45ed-b4eb...

 

Looks like the system is trying to reach UsrWorkers from Contact table. This is the case with my requirement. There is no direct relation between the 2 tables. Would appreciate any suggestion!

 

Here is the code I used

"UsrOwner": {
        "dataValueType": Terrasoft.DataValueType.LOOKUP,
        "lookupListConfig": {
            "filters": [function() {
                var filters = Ext.create("Terrasoft.FilterGroup");
                filters.add("WorkInThisCompany", 
                    Terrasoft.createColumnFilterWithParameter(
                        Terrasoft.ComparisonType.EQUAL,
                        "[UsrWorkers.UsrWorker].UsrAccount.Id",
                        this.get("UsrAccount").value
                    )
                );
                return filters;
            }]
        }

 

Shivani Lakshman,

 

Change the filter from "[UsrWorkers.UsrWorker].UsrAccount.Id" to "[UsrWorkers:UsrWorker].UsrAccount.Id"

 

My bad, I forgot that in reverse join it work using ":", for example :

[EntityCode:FieldCode]

 

and not [EntityCode.FieldCode]

 

regards,

 

Julien

Show all comments