Hi,
I have made a query. Its working fine.
I made 2 options (i) count() query and (ii) var resultCount_out = result.totalCount;. Its working perfectly if the data is available. If there is No data. If its Zero the IF condition is not working. Please find below the code. Need Help
wixData.query('LM_Attendance').eq('at_date', $w('#date').value).eq('at_email', $w("#email").value).descending("at_out")
.count()
.then(result => {
$w("#input1").value = result;
})
.catch((err) => {
let errorMsg = err;
$w("#timedate").text = errorMsg;
});
wixData.query('LM_Attendance').eq('at_date', $w('#date').value).eq('at_email', $w("#email").value).descending("at_out")
.find()
.then(result => {
let item = result.items[0];
$w('#regtimebaseddata').value = item.at_regtime;
$w('#regfulldaydata').value = item.at_regfullday;
var firstout = item.at_out;
var hours = parseInt(firstout.getHours());
var resultCount_out = result.totalCount;
var nullvalue = Number($w("#input1").value);
// $w("#input1").value = resultCount_out;
$w("#input2").value = hours;
if (nullvalue === 0) {
$w("#errorzero").show();
} else if (resultCount_out === 1 && hours !== 0) {
let item = result.items[0];
let at_out = result.items[0].at_out;
let firstout = item.at_out;
$w("#datePicker3").value = firstout;
$w("#checkduration").show;
let it_hours_out = addZero(firstout.getHours());
let it_min_out = addZero(firstout.getMinutes());
$w('#timeout').value = it_hours_out + " " + it_min_out;
} else if (resultCount_out === 1 && hours === 0) {
$w("#erroralready").show();
} else if (resultCount_out > 1) {
let item = result.items[0];
let at_in = result.items[0].at_out;
let firstin = item.at_out;
$w("#datePicker3").value = firstin;
$w("#checkduration").show();
let it_hours = addZero(firstin.getHours());
let it_min = addZero(firstin.getMinutes());
$w('#timeout').value = it_hours + " " + it_min;
}
})
.catch((err) => {
let errorMsg = err;
$w("#timedate").text = errorMsg;
});
Thanks for you swift response
But,
let item = result.items[0];
$w('#regtimebaseddata').value = item.at_regtime;
$w('#regfulldaydata').value = item.at_regfullday;
var firstout = item.at_out;
var hours = parseInt(firstout.getHours());
I would this variable hours and the hours comes from let item = result.items[0]; where in I need this variable to calculate the other functions.
My understanding is - Are you are recommending the below
.find() .then(result => { var resultCount_out = result.totalCount;
if (resultCount_out === 0){ let item = result.items; var firstout = item.at_out; var hours = parseInt(firstout.getHours()); var nullvalue = Number($w("#input1").value); // $w("#input1").value = resultCount_out; $w("#input2").value = hours;
}
hey
right after the result => then you should instead have an if checking if result.totalCount === 0 then dont try setting any values from the item = result.items[0] because that does not exist when there are no results. so always check if totalCount === 0 dont try anything with the resultset else do your stuff.