Escaped Character Error

Hi Plumsail,

I have a drop down field which contains an item with an ampersand "Clinical & Scientific Services". When I select the item from the drop down to filter the list and library control, I get an error:

Here is the code I'm using to filter the list and library control:

//Code will filter the List/Library Control based on Hospital
    FinanceCOHDataTable.ready(function() {
        filterFinanceCOHDTbyHospital();
    });

    //filter List or Library with new value when Search field changes
    fd.field('FinanceCOHHospitalField').$on('change', function() {
        filterFinanceCOHDTbyHospital();
    });
    
    function filterFinanceCOHDTbyHospital(){
                        if(fd.field('FinanceCOHHospitalField').value){
                        //Filters HOSPITAL Column
                        FinanceCOHDataTable.filter = "<Contains><FieldRef Name='Hospital'/><Value Type='Text'>"
                        + fd.field('FinanceCOHHospitalField').value + "</Value></Contains>";
                        }
       
                        else{
                            FinanceCOHDataTable.filter = '';
                                }
                                                
                        FinanceCOHDataTable.refresh();
}

How do I escape the ampersand character in this code?

Thank you!

Dear @DryChips,
Please, try the following:

FinanceCOHDataTable.filter = "<Contains><FieldRef Name='Hospital'/><Value Type='Text'><![CDATA["
                        + fd.field('FinanceCOHHospitalField').value + "]]></Value></Contains>";
1 Like

Thanks Nikita, I knew this would solve the issue but I kept getting a syntax error as I didn't know how to write the string correctly within this CAML query.