Dropdown code working in Run/Preview, BUT not live

Your loading of departments needed a quick tweak.

I’ve added brackets around your map statement. As well I separated the map
into its own statement. This makes it easier to debug and check the result
of the map. I’ve also removed the return statement because it didn’t make sense since you were populating the dropdown from within the query.

I also merged the two items as I was assigning them to the dropdown.
If there is an error, then the dropdown just gets populated with ‘All Departments’, but it still returns and continues.

Here is your fix.

let options = [{value: 'All Departments', label: 'All Departments'}];
wixData.query('Departments')
    .find()
    .then( (res) => {
        if (res.length >0) {
            let dept = res.items.map((department) =>  ({value: department.title, label: department.title}));
            $w('#iDepartment').options = [...options, ...dept];
        } else {
            console.log("There was no records available in [Departments].");
            $w('#iDepartment').options = options;
        }
    })
    .catch ( (error) => {
        console.log("Error trying to read [Departments]. Error is: "+error.message);
        $w('#iDepartment').options = options;
    });