onItemReady not working {SOLVED}

It seems like the onItemReady function for the repeater isn’t working as it is always giving me the error message:
“Wix code SDK error: The “onItemReady” function of “repeater1” threw the following error: Cannot read property ‘substr’ of undefined.”

Can someone please provide assistance to get this issue resolved as soon as possible!

Here’s the section of my code with the issue:
Please note. This is the section of my code with the issue. I already have a general onReady function at the beginning of my code. If you wish to see the full code, kindly indicate.

$w("#dataset4").onReady(() => {
        $w("#repeater1").onItemReady(($item, itemData, index) => {
 let theItem = itemData.biography;
 var shortBiography = theItem.substr(0, 240);
            $item("#text106").text = shortBiography + "...";

 //getting current item from the collection
 let fullName = $item('#dataset4').getCurrentItem();
 //change the text to upper case. 
            $item('#text108').text = fullName.fullName.toUpperCase();

 let theItems = itemData.jobType;
 var shortjobType = theItems.substr(0, 10);
            $item("#text109").text = shortjobType + "";

 if (itemData.fullName === undefined) {
                $item("#container2").collapse();
            }
 
        });
    });

You probably have empty items in your database, so wrap your code inside a condition to handle them like

if (itemData.biography) { }

and

if (itemData.jobType) { }

Oh and this part is terrible:

let fullName = $item('#dataset4').getCurrentItem();
$item('#text108').text = fullName.fullName.toUpperCase();

Give all your variables a unique name, or else you’ll confuse the hell out of the browser and get nasty errors. What it’s probably reading is this, which is nonsensical syntax:

$item(‘#dataset4’).getCurrentItem().$item(‘#dataset4’).getCurrentItem().toUpperCase();

Referring to your first answer. I’m not exactly sure where to place the if conditions you mentioned because I have

if (itemData.fullName === undefined) {
                $item("#container2").collapse();
            }

like so:

let theItem = itemData.biography;
if (theItem) {
       var shortBiography = theItem.substr(0, 240);
       $item("#text106").text = shortBiography + "...";
}

Thank you so much! I’m almost there. Now when I tested it I’m getting a new error message:
Wix code SDK error: The “onItemReady” function of “repeater1” threw the following error: Cannot read property ‘toUpperCase’ of undefined

The code for that part is:

 
//getting current item from the collection
 let FullName = $item('#dataset4').getCurrentItem()
 //change the text to upper case. 
            $item('#text108').text = FullName.fullName.toUpperCase();

Would I use a similar approach like the examples above?

@brit-alexis Yes, the idea is that you replicate this approach anytime you’re referring to a database field that might be empty and thus have an undefined value. If you don’t account for it, the code will fail.

@skmedia thanks for your response. I tried using the same method and I’m still getting the error.

See below:

//getting current item from the collection
 let FullName = $item('#dataset4').getCurrentItem();
 if (FullName) {
 //change the text to upper case. 
            $item('#text108').text = FullName.fullName.toUpperCase();
            }

@brit-alexis Try this, and keep in mind the $item selector applies only to things inside your repeater. Dataset4 is not inside your repeater.

const dynamicName = $w('#dataset4').getCurrentItem().fullName;
 if (dynamicName) {
 //change the text to upper case. 
            $item('#text108').text = dynamicName.toUpperCase();
            }

@skmedia Now it works, partly. But instead of showing the different entries in the database, it’s only showing the last entry.

@brit-alexis If you need more than one item, getCurrentItem is the wrong function to use. You’ll need this:
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getItems

@skmedia After about an hour and a half of researching different articles in the forum and trying different things I finally got it solved. I really appreciate it David. I definitely needed it fixed this weekend.

For anyone else who may be having similar challenges, the final code is:

$w("#dataset4").onReady(() => {
        $w("#repeater1").onItemReady(($item, itemData, index) => {
 let theItem = itemData.biography;
 if (theItem) {
 var shortBiography = theItem.substr(0, 240);
                $item("#text106").text = shortBiography + "...";
            }

 let Items = itemData.jobType;
 if (Items) {
 var shortjobType = Items.substr(0, 10);
                $item("#text109").text = shortjobType + "";
            }

 // new code - you need to change it to something like this
 const totalItems = $w("#dataset4").getTotalCount();

            $w("#dataset4").getItems(0, totalItems)
                .then((results) => {
 let items = itemData.fullName;
 // do something with results 
 if (items) {
 //change the text to upper case. 
                        $item('#text108').text = items.toUpperCase();
                    }
                });

 if (itemData.fullName === undefined) {
                $item("#container2").collapse();
            }
        })
    });

THANKS DAVID!