Filter contacts based on role on Load Data Request not working when Contact is a page parameter.

Hi, 

 

Any ideas why the code below is not working? I get an 'Object reference not set to an instance of an object.' here /0/DataService/json/SyncReply/SelectQuery 

I checked that the getUsersInRole function that I wrote is working. It returns an array of Contact Ids.

Thanks in advance,
Jose

{
    request: 'crt.LoadDataRequest',
    handler: async (request, next) => {
        if (request.dataSourceName === 'PageParameters_UsrLookupParameter1_13p73tg_List_DS') {
            var roleId = request.$context.attributes.PageParameters_UsrLookupParameter1_atde2dj?.value;
            var users = await UsrC2CUtilitiesV2.getUsersInRole(roleId);
            const usersFilter = new sdk.FilterGroup();
            await usersFilter.addSchemaColumnInFilterWithParameters(sdk.ComparisonType.Equal, "Id", users);                            
            request.parameters.push({
                type: "filter",
                value: usersFilter
            });
        }
        return await next?.handle(request);
    }
}

Like 0

Like

3 comments
Best reply

hi Jose,

try to use newFilter instead of usersFilter in the push

// workaround for filters required in Creatio 8.1.0 and older
const newFilter = Object.assign({}, usersFilter);
newFilter.items = usersFilter.items;

Hello,
Just on code alone, it is hard to tell what is the reason for the issue.
You need to do a debug and see at what moment the system cannot read the value.

hi Jose,

try to use newFilter instead of usersFilter in the push

// workaround for filters required in Creatio 8.1.0 and older
const newFilter = Object.assign({}, usersFilter);
newFilter.items = usersFilter.items;

Hi Stefano, 

That fixed my issue. 

Thanks!

Show all comments