[RESOLVED] Lookup field doesn't return Strings with ampersand

Hi Plumsail,

I might have spotted a bug with the Lookup feature.

I have a huge SharePoint Source list which has Departments with ampersands (&) in use and the Auto-populate feature doesn't retrieve the corresponding Hospital.

However, if I click on a department that doesn't include any ampersand it will retrieve the corresponding hospital associated with it.

Here is the code I am using to power the auto-populate feature:

function populateFields() {
    //get CostCenter
    var costCentre = fd.field('Cost_Centre').value;
    //get departments
    var orgL7 = fd.field('Department').value.LookupValue;

    //make sure both values are selected
    if(costCentre && orgL7) {
        var filter = "Cost_x0020_Centre eq '" + costCentre + "' and Org_x0020_L7 eq '" + orgL7 + "'";
        
        //filter list and get item values
        pnp.sp.web.lists.getByTitle('OrgHierarchy').items.filter(filter).get().then(function(item){
            fd.field('Speciality').value = item[0].Id;
            fd.field('Directorate').value = item[0].Id;
            fd.field('Division').value = item[0].Id;
            fd.field('Hospital').value = item[0].Id;
        });
    }
}

    //call function on field change
    fd.field('Cost_Centre').$on('change', populateFields);
    fd.field('Department').$on('change', populateFields);

Here are a few examples of how some departments are named in my organisation:
349 HR & OD
349 L7 Assurance & Compliance
349 L7 N & M Workforce

Dear @DryChips,
Yes, it seems that special characters require encoding. Replace your filter with:
var filter = encodeURIComponent("Cost_x0020_Centre eq '" + costCentre + "' and Org_x0020_L7 eq '" + orgL7 + "'");

1 Like