Can you? Do you get undefined for this? In this way you’ll be able to understand what kind of fields are available there. There is a common mistake when a developer tries to get a field value according to its field_name instead of field_key
undefined is a special value in javascript . It is the value you will get if a variable has not been initialised (i.e. to a value or null) or an object is missing the named property. Basically if the object property is not there then it is undefined :-).
$w("#datasetISW").onReady(() => {
let currentItem = $w('#datasetISW').getCurrentItem();
// Add Eli's proposal
console.log(currentItem);
let hasDoc = currentItem.hasOwnProperty('cvURL');
console.log("cvURL "+(hasDoc?"exists":"does not exist"));
// Does the data set include a cvURL property for the current item?
if (hasDoc) {
$w("#imgCV").show();
$w("#txtCVUnavailable").hide(); console.log("document found");
} else {
$w("#txtCVUnavailable").show(); $w("#imgCV").hide();
console.log("no document found");
}
console.log(hasDoc);
});
Many thanks for your responses. I know that I am using the correct field value and I have implemented the code you suggested, Steve. Allthough it is not returning as undefined it is still saying ‘no document found’. when there is a value in cvURL . Please see screenshot of the console log below…
The code is in the page ISW in the function cvAvailability() which is called in btnSearch_click (but currently commented out). To test the function you need to search for –All Regions– and –All Specialisms– in the drop down fields.
I have a similar issue, but am checking to see if the current item in the dataset has an image instead of a document. I modified the code from @stcroppe, but the site is not collapsing the blank images.
import wixData from 'wix-data';
$w("#dataset1").onReady(() => {
let currentItem = $w('#dataset1').getCurrentItem();
console.log(currentItem);
let hasImage = currentItem.hasOwnProperty('image');
console.log("image "+(hasImage?"exists":"does not exist"));
// Does the data set include a cvURL property for the current item?
if (hasImage) {
$w("#serviceImage").show();
console.log("document found");
} else {
$w("#serviceImage").collapse();
console.log("no document found");
}
console.log(hasImage);
});