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() {

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

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.