Hi community
I want to filter lookup field in detail of a page on the basis of record of another section and the page is in freedom UI and object of that detail is in classic UI
 

Like 0

Like

1 comments

Hello!

 

Thank you for submitting the post on the Community!

 

Could you please provide more details regarding your task so we can better understand what solution we can suggest?  

Show all comments

I am writing to request assistance with applying a filter on a lookup field within a detail while performing inline editing of a record on a Freedom UI page in Creatio. The object of this detail resides in the Classic UI.

Could you please provide guidance on how to achieve this functionality? Any examples, documentation, or step-by-step instructions would be greatly appreciated.

Thank you

Like 0

Like

1 comments

Hello,

 

Please note that this can be setup with the help of business rules, you can find the detailed instructions in this Academy article:
https://academy.creatio.com/docs/8.x/no-code-customization/customization-tools/ui-and-business-logic-customization/freedom-ui-business-rules


You can set it up either for the detail element or for the object itself, you can try the latter to achieve your business goal.

Show all comments

Hi Everyone,

I'm looking to filter a lookup value based on "StartDate" and "EndDate" column field which is present in the lookup object . I attempted to achieve this through the following handler code, where I compare the current date with the End Date. However, it didn't work. Does anyone know of a better approach to filter the lookup value?

Below is my handler code:

{

    request: "crt.LoadDataRequest",

    handler: async (request, next) => {

        // filter the contact lookup for the account

                     

        if (request.dataSourceName !== "LookupAttribute_jw8dbjp_List_DS") {

            return await next?.handle(request);

        }

        // Add filter for UsrEndDate not less than the current date

        const currentDate = new Date();

        const filter = new sdk.FilterGroup(sdk.ComparisonType.And);

        filter.addItem(sdk.Filter.createColumnFilterWithParameter(

            "UsrEndDate",

            sdk.ComparisonType.GreaterThanOrEqual,

            currentDate

        ));

        request.parameters.push({

            type: "filter",

            value: filter

        });

        return await next?.handle(request);

    }

}

Like 0

Like

1 comments

Hello,

Take a look at this discussion, in there you can find an example of how to configure and add a needed filter.

In order to get the exact filter you need, use the test list method described there.

Show all comments

How can we apply custom filters on Lookups in Freedom UI? I can see that there is some existence of a filtersConfig potential property for the object passed as the first parameter to executeRequest, but cannot find any examples or information on how this should be configured in Academy or on other Community questions. We are trying to use this to associate records to a parent record using the + button on a Freedom UI "detail" list, but we don't want any records already associated with any parent by foreign key to be eligible for association using the lookup, and also have some other conditions to apply based on the child entity. Our environment is currently on 8.1 Quantum.

 

Here is the relevant excerpt from the handler on our form page, without any filters applied and with the non-relevant logic applied in the afterClosed area removed for brevity:

request.$context.executeRequest({
	type: "crt.OpenLookupPageRequest",
	$context: request.$context,
	entitySchemaName: "Order",
	caption: "Select Quotes to associate with the Lead",
	features: {
		select: {
			multiple: true,
			selectAll: false,
			resultType: 'lookupValues'
		},
		create: {
			enabled: false
		}
	},
	afterClosed: async function(selectedItems) {
		// logic here
		return next?.handle(request)
	}
});

 

Like 0

Like

5 comments
Best reply

Hello,

Here is an example of OpenLookupPageRequest with a filtersConfig.

handlers: /**SCHEMA_HANDLERS*/[
			{
				request: "usr.OpenLookupRequest",
				handler: async (request, next) => {
					devkit.HandlerChainService.instance.process({
						type: "crt.OpenLookupPageRequest",
						scopes: [...request.scopes],
						$context: request.$context,
						entitySchemaName: "Contact",
						// caption: 'Responsible',
						schemaName: 'CustomLookupPage',
						itemAttributeName: 'LookupAttribute_2mnilrq',
						// itemsAttributeName: 'Contact_List',
						afterClosed: (result) => {
							alert(result?.displayValue ?? '');
						},
						filtersConfig: {
							filterAttributes: [
								{
									name: 'MyFilter',
									loadOnChange: false
								}
							],
							attributesConfig: {
								MyFilter: {
									value: {
										"items": {
											"29e16d42-36f1-4e04-9029-4321cbb2494d": {
												"filterType": 1,
												"comparisonType": 11,
												"isEnabled": true,
												"trimDateTimeParameterToDate": false,
												"leftExpression": {
													"expressionType": 0,
													"columnPath": "Name"
												},
												"isAggregative": false,
												"dataValueType": 1,
												"rightExpression": {
													"expressionType": 2,
													"parameter": {
														"dataValueType": 1,
														"value": "Super"
													}
												}
											}
										},
										"logicalOperation": 0,
										"isEnabled": true,
										"filterType": 6,
										"rootSchemaName": "Contact"
									}
								}
							}
						}
					});
					return next?.handle(request);
				}
			}
		]/**SCHEMA_HANDLERS*/,

If you don't know how to build a proper filter here is a small tip. On a Freedom UI page add a list with the object you want to filter. In this list add a static filter with a condition you want to apply to a OpenLookupPageRequest and save it. As a result, in the code of this page, you can find the full filter code, all you need to do is to replace "MyFilter" with it.

Hello,

Here is an example of OpenLookupPageRequest with a filtersConfig.

handlers: /**SCHEMA_HANDLERS*/[
			{
				request: "usr.OpenLookupRequest",
				handler: async (request, next) => {
					devkit.HandlerChainService.instance.process({
						type: "crt.OpenLookupPageRequest",
						scopes: [...request.scopes],
						$context: request.$context,
						entitySchemaName: "Contact",
						// caption: 'Responsible',
						schemaName: 'CustomLookupPage',
						itemAttributeName: 'LookupAttribute_2mnilrq',
						// itemsAttributeName: 'Contact_List',
						afterClosed: (result) => {
							alert(result?.displayValue ?? '');
						},
						filtersConfig: {
							filterAttributes: [
								{
									name: 'MyFilter',
									loadOnChange: false
								}
							],
							attributesConfig: {
								MyFilter: {
									value: {
										"items": {
											"29e16d42-36f1-4e04-9029-4321cbb2494d": {
												"filterType": 1,
												"comparisonType": 11,
												"isEnabled": true,
												"trimDateTimeParameterToDate": false,
												"leftExpression": {
													"expressionType": 0,
													"columnPath": "Name"
												},
												"isAggregative": false,
												"dataValueType": 1,
												"rightExpression": {
													"expressionType": 2,
													"parameter": {
														"dataValueType": 1,
														"value": "Super"
													}
												}
											}
										},
										"logicalOperation": 0,
										"isEnabled": true,
										"filterType": 6,
										"rootSchemaName": "Contact"
									}
								}
							}
						}
					});
					return next?.handle(request);
				}
			}
		]/**SCHEMA_HANDLERS*/,

If you don't know how to build a proper filter here is a small tip. On a Freedom UI page add a list with the object you want to filter. In this list add a static filter with a condition you want to apply to a OpenLookupPageRequest and save it. As a result, in the code of this page, you can find the full filter code, all you need to do is to replace "MyFilter" with it.

Question on OpenLookupPageRequest. In an edit scenario, could you pass the already selected options so that they appear already selected in the lookup list?

You can use the option selectionState to predefine selected rows, which will be pre-selected

type: "crt.OpenLookupPageRequest",
	...
	selectionState: {
		type: 'specific',
		selected: [
			'9d06bf9f-eb7a-4849-b83d-cbba994f185d',
			'49ba9a9e-2e28-48cb-b1bc-81b7871acb9d',
		],
	},

 

Dmytro Vovchenko,

 

Those are really useful, are there any other parameters that can be passed to the newly opened lookup page? I'm currently looking for a way to automatically set the initial search value of the lookup window, but I'm sure there are many other undocumented useful parameters like the selectionState that can be passed to a lookup page when opening it. A generic way to pass data into the page would be great!

 

I looked into passing a defaultSearchValue parameter into the request, but it didn't seem to affect the modal lookup.

Harvey Adcock,

 

Hello,

 

Here is all the available documentation we have:

 

Lookup window example:

In order to open the lookup window, you have to use crt.OpenSelectionWindowRequest

/**
 * @publicApi
 */
@CrtRequest({
    type: 'crt.OpenSelectionWindowRequest',
})
export class OpenSelectionWindowRequest extends BaseRequest {
    public itemAttributeName?: string;
    public itemsAttributeName?: string;
    /**
     * @publicApi
     */
    public entitySchemaName?: string;
    /**
     * @publicApi
     */
    public schemaName?: string;
    /**
     * @publicApi
     */
    public filtersConfig?: FiltersConfig;
    /**
     * @publicApi
     */
    public features?: PageLookupFeatures;
    /**
     * @publicApi
     */
    public selectionState?: SelectionState;
    /**
     * @publicApi
     */
    public afterClosed?: (result: SelectionWindowResult) => void;
    /**
     * @publicApi
     */
    public caption?: LocalizableString;
}

Add the following code to your custom handler:

handlers: /**SCHEMA_HANDLERS*/[
			{
				request: "usr.OpenLookupRequest",
				handler: async (request, next) => {
					devkit.HandlerChainService.instance.process({
						type: "crt.OpenSelectionWindowRequest",
						scopes: [...request.scopes],
						$context: request.$context,
						entitySchemaName: "Contact",
						// caption: 'Responsible',
						schemaName: 'CustomLookupPage',
						itemAttributeName: 'LookupAttribute_2mnilrq',
						// itemsAttributeName: 'Contact_List',
						afterClosed: async (result) => {
							if (!result.canceled) {
								const lookupValues = await result.getLookupValues();
								const value = lookupValues[0];
								if (value) {
									alert(value?.displayValue ?? '');
								}
							}
						},
						filtersConfig: {
							filterAttributes: [
								{
									name: 'MyFilter',
									loadOnChange: false
								}
							],
							attributesConfig: {
								MyFilter: {
									value: {
										"items": {
											"29e16d42-36f1-4e04-9029-4321cbb2494d": {
												"filterType": 1,
												"comparisonType": 11,
												"isEnabled": true,
												"trimDateTimeParameterToDate": false,
												"leftExpression": {
													"expressionType": 0,
													"columnPath": "Name"
												},
												"isAggregative": false,
												"dataValueType": 1,
												"rightExpression": {
													"expressionType": 2,
													"parameter": {
														"dataValueType": 1,
														"value": "Super"
													}
												}
											}
										},
										"logicalOperation": 0,
										"isEnabled": true,
										"filterType": 6,
										"rootSchemaName": "Contact"
									}
								}
							}
						}
					});
					return next?.handle(request);
				}
			}
		]/**SCHEMA_HANDLERS*/,

where

 

entitySchemaName - the name of the entity schema whose data is displayed in the lookup window. Optional parameter. If not specified, the data source is taken from the attribute specified in itemAttributeName

 

caption - optional parameter, displayed in the window title. If caption is not specified, the caption is taken from the attribute specified in the itemAttributeName parameter. If itemAttributeName is not specified, then from the entity schema.

 

schemaName - the name of the schema that is displayed in the lookup window. Optional parameter. Default is BaseLookupPageTemplate

 

itemAttributeName - the name of the attribute from which the title is taken, the name of the entity schema and in which the result of the selection in the window will be written. Optional parameter. As a rule, this is the attribute with which the Combobox control is associated.

 

itemsAttributeName - the name of the attribute from which the data source name is taken. Optional parameter.

 

afterClosed - callback function returning the result of the selection in the window. Optional parameter.

 

filtersConfig-  describes the filter to be applied to the data. Optional parameter

 

PageLookupFeatures

 

Additionally, the user can specify additional features for the selection window.

export interface PageLookupFeatures {
    create?: {
        enabled: boolean;                         // false by default
    };
    select: {
        multiple: boolean;                        // false by default
        selectAll: boolean;                       // false by default
    };
    showDeactivatedRecords?: boolean;
}

 

The user should provide the Create option as enabled to display the New button in the selection window (only for the FreedomUI host).

devkit.HandlerChainService.instance.process({
	type: "crt.OpenSelectionWindowRequest",
	scopes: [...request.scopes],
	$context: request.$context,
	....
	"features": {
		"create": {
            "enabled": true;
        }
	}
});

 

The New button in this window works best only in the Freedom UI shell. In the Classic UI, new record will be created, but the selection window will close after saving it without passing the created record selected value. If you want to use this window in the Classic UI, please consider it, or don’t show this button there.

 

SelectionWindowResult  type

export class SelectionWindowResult {
    canceled: boolean; // indicates whether selection window was canceled by user
    filter: FilterMetadata; // Filter 
    async getLookupValues(options?: { pagingConfig: DataSourcePagingConfig }): Promise<LookupValue[]>; // method to get lookup values
}

where DataSourcePagingConfig is 

interface DataSourcePagingConfig {
    rowsOffset: number;
    rowCount: number;
}

example

devkit.HandlerChainService.instance.process({
	type: "crt.OpenSelectionWindowRequest",
	scopes: [...request.scopes],
	$context: request.$context,
	....
	"features": {
		"select": {
            "multiple": true;
        }
	},
	afterClosed: async (selectionWindowResult) => {
		const filter = selectionWindowResult.filter // getting filter
		// or 
		const lookupValues = await selectionWindowResult.getLookupValues(); // getting lookupValues
	}
});

 

Multiselection mode

 

To enable multiselection mode user should add next feature to OpenPageLookupRequest

devkit.HandlerChainService.instance.process({
	type: "crt.OpenSelectionWindowRequest",
	scopes: [...request.scopes],
	$context: request.$context,
	....
	features: {
		select: {
            "multiple": true
        }
	}
});

So afterClosed will look like this 

devkit.HandlerChainService.instance.process({
	type: "crt.OpenSelectionWindowRequest",
	scopes: [...request.scopes],
	$context: request.$context,
	....
	features: {
		select: {
			multiple: true
		}
	},
	afterClosed: async (selectionWindowResult) => {
		const lookupValues = await selectionWindowResult.getLookupValues();
		// do something with lookup values
	}
});

 

Select all


To enable the ability to select all records, you should add the next features to OpenPageLookupRequest.

devkit.HandlerChainService.instance.process({
	type: "crt.OpenSelectionWindowRequest",
	scopes: [...request.scopes],
	$context: request.$context,
	....
	features: {
		select: {
            multiple: true,
            selectAll: true
        }
	}
});

 

Canceled
 

Handling cases when the user presses the cancels Selection window

devkit.HandlerChainService.instance.process({
	type: "crt.OpenSelectionWindowRequest",
	scopes: [...request.scopes],
	$context: request.$context,
	....
	features: {
		select: {
			multiple: true
		}
	},
	afterClosed: (selectionWindowResult) => {
		const canceled = selectionWindowResult.canceled;
		if (canceled) {
			// do some logic when user canceled selection window
		}
	}
});

 

Selecting a special set of values


getLookupValues could be called with paging config where user can specify rowsOffset and rowCount to get a specific list of values

devkit.HandlerChainService.instance.process({
	type: "crt.OpenSelectionWindowRequest",
	scopes: [...request.scopes],
	$context: request.$context,
	....
	features: {
		select: {
			multiple: true
		}
	},
	afterClosed: async (selectionWindowResult) => {
		const pagingConfig = {
			rowsOffset: 2,
			rowCount: 2
		}
		const lookupValues = await selectionWindowResult.getLookupValues({ pagingConfig });
		// do something with received lookup values
	}
});

Example of iterating through lookupValues. Getting pair of 2 lookupValues with step of 2

devkit.HandlerChainService.instance.process({
	type: "crt.OpenSelectionWindowRequest",
	scopes: [...request.scopes],
	$context: request.$context,
	....
	features: {
		select: {
			multiple: true
		}
	},
	afterClosed: async (selectionWindowResult) => {
		let rowsOffset = 0;
        const rowCount = 2;
        const pagingConfig = { rowsOffset, rowCount };
        let lookupValues = await selectionWindowResult.getLookupValues({ pagingConfig });
        while (lookupValues.length) {
            /*
              fn(lookupValues); // do something with received lookupValues pair
            */
            rowsOffset += 2;
            lookupValues = await selectionWindowResult.getLookupValues({ pagingConfig: { rowsOffset, rowCount }});
        }
        if (!lookupValues.length) {
            /*
              Do some logic here on end of list - when there are no more lookupValues
            */
        }
	}
});

 

Selection state


and SelectionState is:

{
    type: 'specific';
    selected: unknown[]; // array of id's
}

 

So user can predefine selected rows, which will be pre-selected

devkit.HandlerChainService.instance.process({
	type: "crt.OpenSelectionWindowRequest",
	...
	selectionState: {
		type: 'specific',
		selected: [
			'9d06bf9f-eb7a-4849-b83d-cbba994f185d',
			'49ba9a9e-2e28-48cb-b1bc-81b7871acb9d',
		],
	},
});

 

showDeactivatedRecords


When set to true, deactivated entries of the object are shown.

 

This is all the information that we have on the lookup page handling cases, I hope it helps.

Show all comments

I have a problem filtering a lookup filed using Freedom UI.

The issue here:

The first lookup filed linked to the Contact entity

The second lookup filed's entity Account, contains a field "SMPrimaryAccountOwner" and it should be equal to the first filed value. 



Here is the filter:

 

{
				request: "crt.LoadDataRequest",
				handler: async (request, next) => {
					// filter the contact lookup for the account
					debugger;
					if(request.dataSourceName !== "LookupAttribute_emk4fel_List_DS") {
						return await next?.handle(request);
					}
 
 
					const account = await request.$context.LookupAttribute_r6avpkd;
					if (account) {
						const filter = new sdk.FilterGroup();
						await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "SMPrimaryAccountOwner.Id", account.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: sdk.ModelParameterType.Filter,
							value: filter
						});
					}
 
					return await next?.handle(request);
 
				}
			}



And here is the error on the console:



 

Maybe anyone here had the same issue.

Like 0

Like

2 comments
Best reply

Try changing to just the field "SMPrimaryAccountOwner" and not the ".Id" part at the end.

await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "SMPrimaryAccountOwner", account.value);

Also, even if you're on 8.1 the commented lines are necessary - the issue that works around was *not* fixed in 8.1.

Ryan

Try changing to just the field "SMPrimaryAccountOwner" and not the ".Id" part at the end.

await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "SMPrimaryAccountOwner", account.value);

Also, even if you're on 8.1 the commented lines are necessary - the issue that works around was *not* fixed in 8.1.

Ryan

Try adding the filter for "SMPrimaryAccountOwner" and not "SMPrimaryAccountOwner.Id", as in: 

await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "SMPrimaryAccountOwner", account.value);

Also, the workaround that is commented out is still needed in 8.1. It was not fixed in 8.1.

Ryan

Show all comments

Hello community!

 

I am trying to filter some values of a lookup, and this is the error i get in the console

Does anyone know how can I fix it, or where it's coming from?

Thank you.

Like 0

Like

3 comments

Hi Nicolaiciuc,

 

Can you share the code that you have implemented to filter?

 

Regards,

Sourav

 

Sourav Kumar Samal,

Hello, here is my code:

 

"LbkNewSearchCollateralsInOpp": {

                "dataValueType": Terrasoft.DataValueType.LOOKUP,

                "lookupListConfig": {

                    "filters": [

                        function() {                        

                            // adding the filter to the detail

                            var parentProduct = this.get("OpportunityProductInterest");

                            var filterGroup = Ext.create("Terrasoft.FilterGroup");

                            if (parentProduct) {

                                var parentProductId = parentProduct.value;

                                var subFilters = this.Terrasoft.createFilterGroup();

                                

                                var esq = Ext.create("Terrasoft.EntitySchemaQuery", {

                                    rootSchemaName: "OpportunityProductInterest"

                                });

                                esq.addColumn("Opportunity");

                                esq.getEntity(parentProductId, function(result) {

                                if (result.success) {

                                   

                                    var opportunityId = result.entity.get("Opportunity").Id; 

                                    var newesq = Ext.create("Terrasoft.EntitySchemaQuery", {

                                        rootSchemaName: "LbkProductCollateralTypes"

                                    });

                                    newesq.addColumn("LbkProductCollateralTypesRemainingAllocation");

                                    

                                    var esqFilter = newesq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Opportunity.Id", opportunityId);

                                    newesq.filters.add(esqFilter);

                                    newesq.getEntityCollection(function (newresult) {

                                        if (newresult.success) {

                                          

                                                newresult.collection.each(function (item) {

                                                

                                                   

                                                    var defaultRemainingInBaseCollateral = item.values.LbkProductCollateralTypesRemainingAllocation;

                                                    console.log(defaultRemainingInBaseCollateral);

                                                    subFilters.addItem(this.Terrasoft.createColumnFilterWithParameter(

                                    Terrasoft.ComparisonType.GREATER, defaultRemainingInBaseCollateral, 0));

                                

                                filterGroup.add("Remaining value greater than 0",

                                                Terrasoft.createExistsFilter("[LbkCollateralsNew:LbkNewSearchCollateralsInOpp].Id",

                                                                                subFilters));                                                    

                                                

                                            });

                                        }

                                    }, this);

                                }

                            }, this);

                               

                                

                            }

                            return filterGroup;

                        }

                    ]

                }

            }

Nicolaiciuc Maria,

This won't work. The ESQ query you are attempting is asyncronous, meaning the filter function will return/complete before the ESQ has completed. You'll need to split this into two parts. One part will retrieve the values from LbkProductCollateralTypes and store them in an attribute on the page. This would be called in the onEntityInitialized. The idea is that you're pre-fetching the values from that object beforehand. Then, in the filter function, you'd be reading that attribute to construct and return the FilterGroup as needed, all synchronous since you've already pre-fetched the LbkProductCollateralTypes values in the onEntityInitialized. The filter function won't get called until the lookup is used, so the code in the onEntityInitialized will have completed before then and the LbkProductCollateralTypes values in the attribute will be available by then. Does that make sense? 

Ryan

Show all comments

Hello, community!

This is a selection window for my lookup. Lets take this example, I should not be able to select collaterals that have remaining allocation 0. My problem is that this field is being populated by a process, and the regular lookup filtration does not work. Is there any way to make that select button throw an error/ not let the user save their pick? As in, if remaining allocation equals 0 => select button will do nothing.

Like 0

Like

1 comments

Hello Maria,

Modifying this module window is quite a hard task to do. I believe is your case attribute filter will work just fine:

attributes: {
			"{Your lookup column Name}": {
                "dataValueType": Terrasoft.DataValueType.LOOKUP,
                "lookupListConfig": {
                    "filters": [
                        function() {
                            var filterGroup = Ext.create("Terrasoft.FilterGroup");
                            filterGroup.add("IsNotNull",
                                Terrasoft.createColumnFilterWithParameter(
                                    Terrasoft.ComparisonType.GREATER,
                                    "[{Your lookup column Name}:Id].RemainingAllocation", 0));
                            return filterGroup;
                        }
                    ]
                }
            }
		},

With these records where the remaining allocation is 0 will not be displayed.

Show all comments

Hi Team,



The onLookupDataLoaded: function(config) is not triggered for a custom lookup field in the object. However, the same is triggering for the OOTB lookup columns.



When the control is passed to the lookup, the onLookupDataLoaded event has to trigger but it isn't triggering for custom/newly created lookup in objects.



Are any additional changes required for new lookup columns added to the object?



BR,

Bhoobalna Palanivelu.

Like 0

Like

1 comments

Hi Bhoobalan,

 

This method was triggered for the custom lookup added to the page on my side. Are you sure the method is not triggered?

 

Best regards,

Oscar 

Show all comments

 

 

Hello, I am going to filter only by INN in the lookup, how i can delete other options?

Like 0

Like

0 comments
Show all comments

Hi Community,

 

I have this situation where I need to create a filter for the lookup Group (Fig. 2) based on my custom field that I've created on SysAdminUnit object (Fig.1).

 

Fig. 1

 

 

Fig. 2

 

I've managed to add the custom field to the SysAdminUnitPage (Fig.3). However, the custom field is not "connected" to the object field, because this page is different from the others and does not have entitySchemaName attribute (Fig. 4).

 

Fig.3

 

Fig.4

 

I would like to know:

  1. How can I "connect" the field that I've created on my SysAdminUnitPage to the field I've created on the SysAdminUnit object?
  2. How can I create a filter for the lookup Group inside CasePage using my custom field?

Any suggestion on how to achieve this? Thank you.

 

Best Regards,

Pedro Pinheiro

Like 0

Like

5 comments

Hi Pedro,

 

If you need to create a filter of the Group lookup on the case page then why do you replace the SysAdminUnitPageV2? And which case and account do you expect to see on the SysAdminUnitPageV2 for some role (for example for "System administrators")? Also I cannot see any filtration logic on the SysAdminUnitPageV2 module code you've shared.

 

You need to create a filter on the CasePage using an example provided here.

 

Best regards,

Oscar

Hi Oscar,

 

Thank you for the response.

 

My question consists of two parts:

 

1) I've created a replacing page of the "SysAdminUnitPageV2", so I could add my custom boolean field "Case" and the pre-built lookup field "Account". Since the "Account" field is not custom, I only added the field on my "SysAdminUnitPageV2" page through the “diff” array (image below). Every time I change and save my "Account" value, it will automatically update the value in the database for my specific record. However, the same does not happen to my custom field "Case".

I’ve created the “Case” field the same way "Account" field was created, but I think I'm missing some page logic that is responsible to store my “Case” values in the database.

 

 

2) The lookup filter that I want to add is for the "Group" lookup field inside the "CasePage". This filter should use the "Case" field, previously added to the "SysAdminUnit" object. With the example you provided I was able to complete this second part.

 

 

Best Regards,

Pedro Pinheiro

Pedro Pinheiro,

 

In the Fig.4 modify the "bindTo": "Case" to "bindTo": "UsrCase", save the schema and refresh the "role" page after that. Try saving some value and let me know about the result.

 

Best regards,

Oscar

Oscar Dylan,

 

I've made the changes, but my page cannot find the UsrCase column. I think it's because this page does not have the "entitySchemaName" attribute. But even if I try to add the "entitySchemaName" attribute the page will throw an exception.

 

 

Error Translation: "It was not possible to find the column through the following configuration."

 

 

Best Regards,

Pedro Pinheiro

Pedro Pinheiro,

 

To achieve your first result you need to:

 

1) Create a replacing object selecting the VwSysAdminUnit object as a parent

2) Create the lookup column with the "UsrCase" code and "Case" title inside the object from step 1.

3) Save and publish the object from step 1.

 

As a result here you should get this result:

4) Execute the following query in the database (please note that if you already have customizations in the VwSysAdminUnit table (new columns inside it) then the query that should be executed in your case can differ (all the columns of the already existing replacement should be mentioned in the query, study it before running)):

IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[VwSysAdminUnit]'))
DROP VIEW [dbo].[VwSysAdminUnit]
GO
CREATE VIEW [dbo].[VwSysAdminUnit]
AS
SELECT [SysAdminUnit].[Id]
	,[SysAdminUnit].[CreatedOn]
	,[SysAdminUnit].[CreatedById]
	,[SysAdminUnit].[ModifiedOn]
	,[SysAdminUnit].[ModifiedById]
	,[SysAdminUnit].[Name]
	,[SysAdminUnit].[Email]
	,[SysAdminUnit].[Description]
	,[SysAdminUnit].[ParentRoleId]
	,[SysAdminUnit].[ContactId]
	,[SysAdminUnit].[IsDirectoryEntry]
	,[TimeZone].[Id] AS [TimeZoneId]
	,[SysAdminUnit].[UserPassword]
	,[SysAdminUnitType].[Id] AS [SysAdminUnitTypeId]
	,[SysAdminUnit].[AccountId]
	,[SysAdminUnit].[Active]
	,[SysAdminUnit].[LoggedIn]
	,[SysAdminUnit].[SynchronizeWithLDAP]
	,[LDAPElement].[Name] as [LDAPEntry]
	,[LDAPElement].[LDAPEntryId]
	,[LDAPElement].[LDAPEntryDN]
	,[SysAdminUnit].[SysCultureId]
	,[SysAdminUnit].[ProcessListeners]
	,[SysAdminUnit].[PasswordExpireDate]
	,[SysAdminUnit].[HomePageId]
	,[SysAdminUnit].[ConnectionType]
	,[ConnectionType].[Id] AS [UserConnectionTypeId]
	,[SysAdminUnit].[ForceChangePassword]
	,[SysAdminUnit].[LDAPElementId]
	,[SysAdminUnit].[DateTimeFormatId]
	,[SysAdminUnit].[Id] as [SysAdminUnitId]
	,[SysAdminUnit].[SessionTimeout] as [SessionTimeout]
	,[SysAdminUnit].[UsrCaseId] as [UsrCaseId]
FROM [SysAdminUnit]
INNER JOIN [SysAdminUnitType] ON [SysAdminUnitType].[Value] = [SysAdminUnit].[SysAdminUnitTypeValue]
LEFT JOIN [ConnectionType] AS [ConnectionType] ON [ConnectionType].[Value] = [SysAdminUnit].[ConnectionType]
LEFT JOIN [TimeZone] AS [TimeZone] ON [TimeZone].[Code] = [SysAdminUnit].[TimeZoneId]
LEFT JOIN [LDAPElement] ON [LDAPElement].[Id] = [SysAdminUnit].[LDAPElementId]
GO
CREATE TRIGGER [dbo].[ITR_VwSysAdminUnit_I]
ON [dbo].[VwSysAdminUnit]
	INSTEAD OF INSERT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO [SysAdminUnit](
	[Id]
	,[CreatedOn]
	,[CreatedById]
	,[ModifiedOn]
	,[ModifiedById]
	,[Name]
	,[Email]
	,[Description]
	,[ParentRoleId]
	,[ContactId]
	,[IsDirectoryEntry]
	,[TimeZoneId]
	,[UserPassword]
	,[SysAdminUnitTypeValue]
	,[AccountId]
	,[Active]
	,[LoggedIn]
	,[SynchronizeWithLDAP]
	,[LDAPEntry]
	,[LDAPEntryId]
	,[LDAPEntryDN]
	,[SysCultureId]
	,[ProcessListeners]
	,[PasswordExpireDate]
	,[HomePageId]
	,[ConnectionType]
	,[ForceChangePassword]
	,[LDAPElementId]
	,[DateTimeFormatId]
	,[SessionTimeout]
	,[UsrCaseId])
SELECT [Id]
	,[CreatedOn]
	,[CreatedById]
	,[ModifiedOn]
	,[ModifiedById]
	,[Name]
	,[Email]
	,[Description]
	,[ParentRoleId]
	,[ContactId]
	,[IsDirectoryEntry]
	,(SELECT COALESCE(
		(SELECT [TimeZone].[Code] FROM [TimeZone]
			WHERE [TimeZone].[Id] = [INSERTED].[TimeZoneId]), ''))
	,[UserPassword]
	,ISNULL((SELECT [SysAdminUnitType].[Value] FROM [SysAdminUnitType]
		WHERE [SysAdminUnitType].[Id] = [INSERTED].[SysAdminUnitTypeId]), 4)
	,[AccountId]
	,[Active]
	,ISNULL([LoggedIn], 0)
	,[SynchronizeWithLDAP]
	,(SELECT COALESCE(
		(SELECT [LDAPElement].[Name] FROM [LDAPElement]
			WHERE [LDAPElement].[Id] = [INSERTED].[LDAPElementId]), ''))
	,(SELECT COALESCE(
		(SELECT [LDAPElement].[LDAPEntryId] FROM [LDAPElement]
			WHERE [LDAPElement].[Id] = [INSERTED].[LDAPElementId]), ''))
	,(SELECT COALESCE(
		(SELECT [LDAPElement].[LDAPEntryDN] FROM [LDAPElement]
			WHERE [LDAPElement].[Id] = [INSERTED].[LDAPElementId]), ''))
	,[SysCultureId]
	,[ProcessListeners]
	,[PasswordExpireDate]
	,[HomePageId]
	,COALESCE([INSERTED].[ConnectionType],
		(SELECT [ConnectionType].[Value] FROM [ConnectionType]
		WHERE [ConnectionType].[Id] = [INSERTED].[UserConnectionTypeId]), 0)
	,ISNULL([ForceChangePassword], 0)
	,[LDAPElementId]
	,[DateTimeFormatId]
	,[SessionTimeout]
	,[UsrCaseId]
FROM [INSERTED]
END
GO
CREATE TRIGGER [dbo].[ITR_VwSysAdminUnit_U]
ON [dbo].[VwSysAdminUnit]
	INSTEAD OF UPDATE
AS
BEGIN
SET NOCOUNT ON;
UPDATE [SysAdminUnit]
SET [SysAdminUnit].[CreatedOn] = [INSERTED].[CreatedOn]
	,[SysAdminUnit].[CreatedById] = [INSERTED].[CreatedById]
	,[SysAdminUnit].[ModifiedOn] =[INSERTED].[ModifiedOn]
	,[SysAdminUnit].[ModifiedById] = [INSERTED].[ModifiedById]
	,[SysAdminUnit].[Name] = [INSERTED].[Name]
	,[SysAdminUnit].[Email] = [INSERTED].[Email]
	,[SysAdminUnit].[Description] = [INSERTED].[Description]
	,[SysAdminUnit].[ParentRoleId] = [INSERTED].[ParentRoleId]
	,[SysAdminUnit].[ContactId] = [INSERTED].[ContactId]
	,[SysAdminUnit].[IsDirectoryEntry] = [INSERTED].[IsDirectoryEntry]
	,[SysAdminUnit].[TimeZoneId] =
		(SELECT COALESCE(
			(SELECT [TimeZone].[Code] FROM [TimeZone]
				WHERE [TimeZone].[Id] = [INSERTED].[TimeZoneId]), ''))
	,[SysAdminUnit].[UserPassword] = [INSERTED].[UserPassword]
	,[SysAdminUnit].[SysAdminUnitTypeValue] =
		(SELECT [SysAdminUnitType].[Value] FROM [SysAdminUnitType]
			WHERE [SysAdminUnitType].[Id] = [INSERTED].[SysAdminUnitTypeId])
	,[SysAdminUnit].[AccountId] = [INSERTED].[AccountId]
	,[SysAdminUnit].[Active] = [INSERTED].[Active]
	,[SysAdminUnit].[LoggedIn] = [INSERTED].[LoggedIn]
	,[SysAdminUnit].[SynchronizeWithLDAP] = [INSERTED].[SynchronizeWithLDAP]
	,[SysAdminUnit].[LDAPEntry] =
		CASE
			WHEN (UPDATE(SynchronizeWithLDAP) AND [INSERTED].[SynchronizeWithLDAP] = 1 AND [INSERTED].[LDAPElementId] is not null)
					OR (UPDATE(LDAPElementId) AND [INSERTED].[LDAPElementId] is not null)
				THEN (SELECT [LDAPElement].[Name] FROM [LDAPElement] WHERE [LDAPElement].[Id] = [INSERTED].[LDAPElementId])
			WHEN UPDATE(SynchronizeWithLDAP) AND [INSERTED].[SynchronizeWithLDAP] = 0
				THEN ''
			ELSE [SysAdminUnit].[LDAPEntry]
		END
	,[SysAdminUnit].[LDAPEntryId] = 
		CASE
			WHEN (UPDATE(SynchronizeWithLDAP) AND [INSERTED].[SynchronizeWithLDAP] = 1 AND [INSERTED].[LDAPElementId] is not null)
					OR (UPDATE(LDAPElementId) AND [INSERTED].[LDAPElementId] is not null)
				THEN (SELECT [LDAPElement].[LDAPEntryId] FROM [LDAPElement] WHERE [LDAPElement].[Id] = [INSERTED].[LDAPElementId])
			WHEN UPDATE(SynchronizeWithLDAP) AND [INSERTED].[SynchronizeWithLDAP] = 0
				THEN ''
			ELSE [SysAdminUnit].[LDAPEntryId]
		END
	,[SysAdminUnit].[LDAPEntryDN] = 
		CASE
			WHEN (UPDATE(SynchronizeWithLDAP) AND [INSERTED].[SynchronizeWithLDAP] = 1 AND [INSERTED].[LDAPElementId] is not null)
					OR (UPDATE(LDAPElementId) AND [INSERTED].[LDAPElementId] is not null)
				THEN (SELECT [LDAPElement].[LDAPEntryDN] FROM [LDAPElement] WHERE [LDAPElement].[Id] = [INSERTED].[LDAPElementId])
			WHEN UPDATE(SynchronizeWithLDAP) AND [INSERTED].[SynchronizeWithLDAP] = 0
				THEN ''
			ELSE [SysAdminUnit].[LDAPEntryDN]
		END
	,[SysAdminUnit].[SysCultureId] = [INSERTED].[SysCultureId]
	,[SysAdminUnit].[ProcessListeners] = [INSERTED].[ProcessListeners]
	,[SysAdminUnit].[PasswordExpireDate] = [INSERTED].[PasswordExpireDate]
	,[SysAdminUnit].[HomePageId] = [INSERTED].[HomePageId]
	,[SysAdminUnit].[ConnectionType] = COALESCE([INSERTED].[ConnectionType],
		(SELECT [ConnectionType].[Value] FROM [ConnectionType]
		WHERE [ConnectionType].[Id] = [INSERTED].[UserConnectionTypeId]), 0)
	,[SysAdminUnit].[ForceChangePassword] = [INSERTED].[ForceChangePassword]
	,[SysAdminUnit].[LDAPElementId] = [INSERTED].[LDAPElementId]
	,[SysAdminUnit].[DateTimeFormatId] = [INSERTED].[DateTimeFormatId]
	,[SysAdminUnit].[SessionTimeout] = [INSERTED].[SessionTimeout]
	,[SysAdminUnit].[UsrCaseId] = [INSERTED].[UsrCaseId]
FROM [SysAdminUnit]
INNER JOIN [INSERTED] ON [SysAdminUnit].[Id] = [INSERTED].[Id]
END
GO
CREATE TRIGGER [dbo].[ITR_VwSysAdminUnit_D]
ON [dbo].[VwSysAdminUnit]
	INSTEAD OF DELETE
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM [SysAdminUnit]
WHERE EXISTS(SELECT * FROM [DELETED] WHERE [SysAdminUnit].[Id] = [DELETED].[Id])
END
GO

This query is for MS SQL, if your application is hosted using the PostgreSQL database then your query should be written using PostgreSQL syntax (you can copy the OOB VwSysAdminUnitPostgreSql SQL-script from the LDAP package, add your custom columns inside the ready script and execute it after that).

 

5) In the replaced SysAdminUnitPageV2 module add the following code to the diff array of the module:

{
					"operation": "insert",
					"parentName": "Header",
					"propertyName": "items",
					"name": "UsrCase",
					"values": {
						"bindTo": "UsrCase",
						"dataValueType": this.Terrasoft.DataValueType.LOOKUP,
						"layout": {
							"column": 0,
							"row": 1,
							"colSpan": 24
						}
					},
				}

6) Add the entitySchemaName: "VwSysAdminUnit", part to the replaced SysAdminUnitPageV2 module (below you can find an example of the correctly replaced module):

define("SysAdminUnitPageV2", [],
	function() {
		return {
			entitySchemaName: "VwSysAdminUnit",
			details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
			diff: /**SCHEMA_DIFF*/[
				{
					"operation": "insert",
					"parentName": "Header",
					"propertyName": "items",
					"name": "UsrCase",
					"values": {
						"bindTo": "UsrCase",
						"dataValueType": this.Terrasoft.DataValueType.LOOKUP,
						"layout": {
							"column": 0,
							"row": 1,
							"colSpan": 24
						}
					},
				}
			]/**SCHEMA_DIFF*/,
			attributes: {},
			methods: {}
		};
});

7) Save the module and refresh the page

 

As a result you will get a working lookup that references the "Case" object:

and

PS: also please share code itself, but not its screenshots, sometimes copying some ready code can save the time:)

 

Best regards,

Oscar

Show all comments