TypeError: Cannot read property '[Field Key]' of null

I have a dynamic page on my site that contains several elements that are supposed to display only if the data cells they correspond to are populated with data (i.e. elements that connect to empty data cells should collapse on the live pages).

We had implemented some script (see below) which was functioning properly until recently to make this happen. Now, however, all of the elements are displaying regardless of whether their data cells have content or not, and I’m getting the error message “TypeError: Cannot read property ‘[Field Key here]’ of null” for every element the code is meant to reference.

This is an example of the original script my past web developer wrote. In this case, “waiver2” is the Field Key of the data cell that the script is supposed to reference, and “button18” is the collapsing element.

$w.onReady(function () {
var doc = $w(“#dynamicDataset”).getCurrentItem().waiver2;
if(doc === undefined) {
$w(“#button18”).collapse();
}
});

I’m not sure if this is a script issue, if something has changed with Corvid, or what, but I’d really appreciate any insight into this! Let me know if you need anything more from me to look into it. Thanks!

You’re missing:

$w.onReady(function () {
$w("#dynamicDataset").onReady(() => {
var doc = $w("#dynamicDataset").getCurrentItem().waiver2;
if(doc === undefined) {
$w("#button18").collapse();
}
})
});