Lookup Filter doesn't work as expected

Hey,
I'm using SP 2019 on Prem with the designer 1.8.7 and I'm trying to use the filter function as described here https://plumsail.com/blog/lookup-filter

I've created a simple control in Plumsail Designer which is named Toggle1.

In a function which runs on a onchange event of another field, I have the following line:
fd.field('Toggle1').value = true;

The Toggle1 is set to yes as it should.

In the filter field of the Lookup I have the following setting:

image

Ausleihbar is a Yes/No field in the lookup list.

By setting the Toggle1 through the above mentioned code it doesn't work. When i toggle the Toggle1 manually by clicking on it, it works just as expected. Is there anything I can do about that? The filter should ideally happen automatically.

Dear JonHebbe,
Are you sure about this? Can you check the browser's console for errors?

This should work, just reproduced the setup on our tenant:

Hey @Nikita_Kurguzov
heres a short gif about my problem.

//GIF deleted for privacy reasons

The 3004 is the only car which has "true" in field "Ausleihbar"

Console output of the video, so no errors

Dear @JonHebbe,
I am not able to reproduce this result. Here's my code that you can try:

fd.spRendered(function(){
  fd.field('Title').$on('change',function(value){
    if(value){
      fd.field('Toggle1').value = true;
    }
    else{
      fd.field('Toggle1').value = false;
    }
  });
});

Can you share your code so that we can test it?

Hey @Nikita_Kurguzov - of course, this is the code. It's basically the same code for the Toggle value you also have.
"Fahrzeugauswahl" is the lookup field.

fd.spRendered(function() {
fd.field('Fahrzeugauswahl').disabled = true;
function filtervehicles() {
    fd.field('Fahrzeugauswahl').value = "";
    fd.field('Toggle1').value = true;
    var tempEventDate = fd.field('EventDate').value; 
    var tempEndDate = fd.field('EndDate').value;
    var wantedEventDate = tempEventDate.toISOString();
    var wantedEndDate = tempEndDate.toISOString();
    var list = pnp.sp.web.lists.getByTitle("Fahrzeugreservierung");
    list.items.filter("EndDate gt '" + wantedEventDate + "' and EventDate lt '" + wantedEndDate + "'").get().then(function(items){
        var vehIDs = items.map(function(i) { return i.FahrzeugauswahlId});
        console.log(vehIDs);
        if(vehIDs.length > 0){
            var filterString = "Id ne " + vehIDs.join(" and Id ne ");
            fd.field('Fahrzeugauswahl').filter = filterString;
            fd.field('Fahrzeugauswahl').refresh();
        }
        else{
            var filterString = "";
            fd.field('Fahrzeugauswahl').filter = filterString;
            fd.field('Fahrzeugauswahl').refresh();
        }
    });
    console.log("wantedEventDate: " + wantedEventDate);
    console.log("wantedEndDate: " + wantedEndDate);
    fd.field('Fahrzeugauswahl').disabled = false;
}
	fd.field('EventDate').$on('change',filtervehicles);
fd.field('EndDate').$on('change',filtervehicles);
});

Dear @JonHebbe,
Are you applying a custom filter in your code to the same field?
fd.field('Fahrzeugauswahl').filter = filterString;
This would overwrite the settings you have in the editor.

Yes I do, I check if a car is free for the time slot that is provided (EventDate / EndDate) and after that I filter all cars with the filterString.

Is there anything I can change in the following code so that the field "Ausleihbar" has to be true in the filter?

 var filterString = "Id ne " + vehIDs.join(" and Id ne ");

Dear @JonHebbe,
Yes, you'll need the code adjusted to also check for the Toggle value.

var toggle = fd.field('Toggle1').value ? 1 : 0;
var filterString = "...your filter here..." + "and Ausleihbar eq " + toggle;

Use the Internal Name of the Ausleihbar field.

Thank you very much, it works as expected now.

Sorry for the inconvenience.

1 Like