Has crt.OpenSelectionWindowRequest replaced crt.OpenLookupPageRequest in 8.1.3?
It looks like in 8.1.3, when clicking the magnifying glass on a lookup field which is configured to show the lookup page modal popup, the handler crt.OpenSelectionWindowRequest is now called instead of crt.OpenLookupPageRequest. Is is the case that the old handler has been swapped for the new one? Why has this been done? And are there any important differences to be noted? It's broken some of our client's custom code in the upgrade, and from a surface view it looks like it works in much the same way as the old handler and that simply swapping the code to use the new handler instead of the old works, but don't want to make any assumptions on that. Anybody have any insight on this?
Like
Hmm. Good find. I’ll have some broken customizations as well. Hopefully we’ll get an official word about the change. This isn’t the first time I’ve had things break from changes to core Freedom UI things. I like using Freedom UI but at times it feels like a moving target. We need some commitment from Creatio about avoiding breaking changes.
Ryan
Hi Harvey,
I just tested this in an 8.1.3.6734 system and both "crt.OpenSelectionWindowRequest" and "crt.OpenLookupPageRequest" did open the selection/lookup window for me. However, using the results seemed to work differently depending on which request I used, it didn't work to just change the request name and leave the rest of the code as-is. So they do appear to possibly be slightly different requests, at least from my very limited tests so far 🤷🏼♂️
Ryan
Interesting, thanks for the additional info Ryan! For triggering the lookup page from code I think we'll stick with the original method for now then.
But a little PSA for anyone wondering why their code overriding the crt.OpenLookupPageRequest handler to intercept and add filters/perform other logic when a user triggers a lookup page on a lookup field configured to view as "Selection window" rather than dropdown list, they should now be overriding crt.OpenSelectionWindowRequest instead. Hopefully we'll get some clarification on why this has changed and any implications.
Harvey Adcock,
8.1.3 is the first release with this API published, and Creatio mentioned the API for Freedom UI selection window in the 8.1.3 release notes. At the same time, we left it without changes so as not to break possible customizations with the old unpublished API. However, the old API is effectively deprecated, and the new API should be used from now on.
The full article for the Academy is almost ready and will be officially published soon.
Here is part of main information (maybe some parts will be changed, that's why please follow the updates):
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
P.S. Additionally, users can enable features and much more, which you're able to read from the article on the Academy in the near future.
Anhelina,
Hi!
How i can filter SelectionWindow by using value from lookup field on page?
I try this:
{ request: "usr.AddSection", handler: async (request, next) => { const id = request.$context.PDS_Transport2_93i8xm8; request.$context.executeRequest({ type: "crt.OpenLookupPageRequest", $context: request.$context, entitySchemaName: "Section", features: { select: { multiple: true, selectAll: false, resultType: 'lookupValues' }, create: { enabled: false } }, 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": "Transport" }, "isAggregative": false, "dataValueType": 1, "rightExpression": { "expressionType": 2, "parameter": { "dataValueType": 1, "value": id.value } } } }, "logicalOperation": 0, "isEnabled": true, "filterType": 6, "rootSchemaName": "Section" } } } }, afterClosed: function(selectedItems) { const textValues = Object.values(selectedItems).map(item => item.displayValue).join(', '); request.$context.PDS_SectionUpload_h11bk0p = textValues; } }); } }
but always get error: The data types nvarchar and uniqueidentifier are incompatible in the add operator.
Grygorii Synieok,
You forgot to await the value when getting the attribute.
Change to this (note the added "await"):
const id = await request.$context.PDS_Transport2_93i8xm8;
Ryan
Ryan Farley,
Thank you!
But another problem was with: "dataValueType":10 and "comparisonType":3 with this parametrs works fine.
Full code:
{ request: "usr.AddSection", handler: async (request, next) => { var autoId = await request.$context.PDS_UsrTransport2; request.$context.executeRequest({ type: "crt.OpenLookupPageRequest", $context: request.$context, entitySchemaName: "SectionAuto", features: { select: { multiple: true, selectAll: false, resultType: 'lookupValues' }, create: { enabled: false } }, filtersConfig: { filterAttributes: [ { name: 'MyFilter', loadOnChange: false } ], attributesConfig: { MyFilter: { value: { "items": { "29e16d42-36f1-4e04-9029-4321cbb2494d": { "filterType": 1, "comparisonType":3, "isEnabled": true, "trimDateTimeParameterToDate": false, "leftExpression": { "expressionType": 0, "columnPath": "Transport" }, "isAggregative": false, //"dataValueType": 1, "rightExpression": { "expressionType": 2, "parameter": { "dataValueType": 10, "value":autoId.value } } } }, "logicalOperation": 0, "isEnabled": true, "filterType": 6, "rootSchemaName": "SectionAuto" } } } }, afterClosed: function(selectedItems) { const textValues = Object.values(selectedItems).map(item => item.displayValue).join(', '); request.$context.PDS_UsrSection = textValues; } }); } }
Hello Harvey,
I've a 8.1.3 environment and on some pages the crt.OpenLookupPageRequest works correctly while on other pages it doesn't open the required lookup
Do you have the same issue ?