Filter List/Library using Choice Field

Hello Plumsail Community!

I want to filter the list/library control using the Choice field. I haven't found an example of this scenario in the community so I thought I would ask.

Here is the code that I am working with but is not doing anything:

//Code will filter the List/Library Control based on Report_Type Choice field
    var dt = fd.control('SPDataTable1');
    dt.ready(function() {
        filterDT();
    });

    //filter List or Library with new value when Search field changes
    fd.field('Search').$on('change', function() {
        filterDT();
    });
    
    function filterDT(){
                        if(fd.field('Search').value){
                        dt.filter = "<Eq><FieldRef Name='Report_Type'/><Value Type='Text'>"
                        + fd.field('Search').value + "</Value></Eq>";
                        }
                        
                        else{
                            dt.filter = '';
                                }
                                                
                        dt.refresh();
}

Dear @DryChips,
Is it a single choice or multi choice field? The code above should work for a single choice from the looks of it, but it will not for multi choice.

Also, it is the Report_Type the choice type field, right?

That's correct.

The field is a Single Choice field, I have tried using this but it doesn't seem to be working. It does look like its doing something in the background but nothing obvious.

Dear @DryChips,
Try using <Value Type='Choice'> instead

Tried this as well, here is a video of what's happening on my end:

Dear @Qman,
Strange video format, requires connection to some server, we're unable to open it.

This functionality uses a standard CAML query, here's the schema for it - Query schema in CAML | Microsoft Docs

Try using a static value in JS code instead of a search field value first. Once you get it working with static value, try replacing it with search field value.

Check this out:

Video.wmv (1.7 MB)

Dear @Qman,
This doesn't give me anything, apart from the fact that the filter is not working properly. The important part is - what's the type of Report_Type field used in List or Library?

Not the DropDown1 you have on the form, but the Report_Type in another list.

Can you open Report_Type field column in list settings and show it to me?
Like this for Report_Type field:

Hi Nikita,

Please see below:

The list/library is referencing the form's SharePoint List. The form will provide HR an ability to add/remove people from a SharePoint list as they will have access to the PowerBi repots.

Dear @Qman,
Maybe, the problem is the Internal Name of the field, please, check it in the URL:

The following code works for me:

fd.spRendered(function(){
    //Code will filter the List/Library Control based on Report_Type Choice field
    var dt = fd.control('SPDataTable1');
    dt.ready(function() {
        filterDT();
    });

    //filter List or Library with new value when Search field changes
    fd.field('Report_Type').$on('change', function() {
        filterDT();
    });
    
    function filterDT(){
        if(fd.field('Report_Type').value){
        dt.filter = "<Eq><FieldRef Name='Report_Type'/><Value Type='Text'>"
        + fd.field('Report_Type').value + "</Value></Eq>";
        }
        
        else{
            dt.filter = '';
                }
                                
        dt.refresh();
    }
});

Video attached:

I've used the same Report_Type field for filtering, but it should work with Search field just as well.

Ah, I think I know what the problem is.

My colleague @DryChips is thinking of creating an New and Edit version form into one form as only certain people will access this form. I will explain to her that a New and Edit version will need to be created for this functionality to work.

Ah, the reason why it didn't work was because of the function name. So simple. The function names need to be unique otherwise it will clash with each other.

Thank you for your help!