Filtering dropdown data in handler

Hi Community,

 

I’m working on filtering dropdown data. I need to show only those contacts who had no activity between the given start date and end date in Remote Support object, but it doesn't work. For example, I've got error: "Between must contain two expressions in the left part", but I'm not using between

 

Could you help me with this? 
Thank you in advance!


Handler's code:

 

 handlers: /**SCHEMA_HANDLERS*/ [{
 
            request: "crt.LoadDataRequest",
            handler: async (request, next) => {
                if (request.dataSourceName !== "PDS_RvcFieldEngineer_x610q2p_List_DS") {
                    return await next?.handle(request);
                }
 
                debugger;
 
                var startDate = await request.$context.attributes.PDS_RvcStartDate_uv0hce9;
                var endDate = await request.$context.attributes.PDS_RvcEndDate_bxhjbvc;
 
                console.log("Start Date:", startDate);
 
                if (!startDate || !endDate) {
                    return [];
                }
 
                const activityModel = await sdk.Model.create("Activity");
                const activityFilter = new sdk.FilterGroup();
 
                activityFilter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.LessOrEqual, "DueDate", endDate);
                activityFilter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.GreaterOrEqual, "StartDate", startDate);
 
                var newFilter = Object.assign({}, activityFilter);
                newFilter.items = activityFilter.items;
 
                const activityDetails = await activityModel.load({
                    attributes: ["Id", "Owner"],
                    parameters: [{
                        type: sdk.ModelParameterType.Filter,
                        value: newFilter
                    }]
                });
 
                const ownerIds = activityDetails
                    .map(activity => activity.Owner?.value)
                    .filter(id => id);
 
                const contactModel = await sdk.Model.create("Contact");
                const contactFilter = new sdk.FilterGroup();
 
                console.log(ownerIds.length);
 
                if (ownerIds.length === 0) {
                    contactFilter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.IsNotNull, "Id", null);
                } else {
                    contactFilter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.NotIn, "Id", ownerIds);                
		}
 
                const contactDetails = await contactModel.load({
                    attributes: ["Name"],
                    parameters: [{
                        type: sdk.ModelParameterType.Filter,
                        value: contactFilter
                    }]
                });
 
                return contactDetails.map(contact => ({
                    id: contact.Id.value,
                    name: contact.Name.value
                }));
 
                request.parameters.push({
                    type: "filter",
                    value: newFilter
                });
 
 
                return await next?.handle(request);
            }
        }] /**SCHEMA_HANDLERS*/ ,

 

Like 0

Like

2 comments

Hello Agnieszka,

To fix the issue you should change the property: 

1) sdk.ComparisonType.LessOrEqual to sdk.ComparisonType.Less_or_equal   

2) sdk.ComparisonType.GreaterOrEqual to sdk.ComparisonType.Greater_or_equal

Good practice is to check if the property exists with the console:

Anhelina,

Thank you, it worked but there is a problem with creating models now.

Show all comments