# onItemReady not working {SOLVED}

**URL:** <https://forum.wixstudio.com/t/onitemready-not-working-solved/17479>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [July 12, 2019, 5:13pm UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479 "2019-07-12T17:13:38Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![brit-alexis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@brit-alexis](https://forum.wixstudio.com/u/brit-alexis)\
**Post date:** [July 12, 2019, 5:13pm UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/1 "2019-07-12T17:13:38Z")

</div>

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.**

```javascript
$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();
            }
 
        });
    });

```

---

<div class="post-metadata">

**Author:** ![skmedia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/skmedia/32/5616_2.png) [@skmedia](https://forum.wixstudio.com/u/skmedia)\
**Post date:** [July 13, 2019, 1:44am UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/2 "2019-07-13T01:44:01Z")

</div>

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

```javascript
if (itemData.biography) { }

```

and

```javascript
if (itemData.jobType) { }

```

---

<div class="post-metadata">

**Author:** ![skmedia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/skmedia/32/5616_2.png) [@skmedia](https://forum.wixstudio.com/u/skmedia)\
**Post date:** [July 13, 2019, 1:45am UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/3 "2019-07-13T01:45:49Z")

</div>

Oh and this part is terrible:

```javascript
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();

---

<div class="post-metadata">

**Author:** ![brit-alexis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@brit-alexis](https://forum.wixstudio.com/u/brit-alexis)\
**Post date:** [July 13, 2019, 2:17am UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/4 "2019-07-13T02:17:23Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![skmedia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/skmedia/32/5616_2.png) [@skmedia](https://forum.wixstudio.com/u/skmedia)\
**Post date:** [July 13, 2019, 2:30am UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/5 "2019-07-13T02:30:45Z")

</div>

like so:

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

```

---

<div class="post-metadata">

**Author:** ![brit-alexis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@brit-alexis](https://forum.wixstudio.com/u/brit-alexis)\
**Post date:** [July 13, 2019, 2:56am UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/6 "2019-07-13T02:56:51Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![brit-alexis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@brit-alexis](https://forum.wixstudio.com/u/brit-alexis)\
**Post date:** [July 13, 2019, 1:22pm UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/7 "2019-07-13T13:22:16Z")

</div>

Would I use a similar approach like the examples above?

---

<div class="post-metadata">

**Author:** ![skmedia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/skmedia/32/5616_2.png) [@skmedia](https://forum.wixstudio.com/u/skmedia)\
**Post date:** [July 13, 2019, 8:16pm UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/8 "2019-07-13T20:16:32Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![brit-alexis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@brit-alexis](https://forum.wixstudio.com/u/brit-alexis)\
**Post date:** [July 13, 2019, 8:25pm UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/9 "2019-07-13T20:25:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brit-alexis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@brit-alexis](https://forum.wixstudio.com/u/brit-alexis)\
**Post date:** [July 13, 2019, 8:34pm UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/10 "2019-07-13T20:34:22Z")

</div>

See below:

```javascript
//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();
            }

```

---

<div class="post-metadata">

**Author:** ![skmedia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/skmedia/32/5616_2.png) [@skmedia](https://forum.wixstudio.com/u/skmedia)\
**Post date:** [July 13, 2019, 9:09pm UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/11 "2019-07-13T21:09:57Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![brit-alexis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@brit-alexis](https://forum.wixstudio.com/u/brit-alexis)\
**Post date:** [July 13, 2019, 9:31pm UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/12 "2019-07-13T21:31:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![skmedia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/skmedia/32/5616_2.png) [@skmedia](https://forum.wixstudio.com/u/skmedia)\
**Post date:** [July 14, 2019, 1:17am UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/13 "2019-07-14T01:17:31Z")

</div>

@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](https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getItems)

---

<div class="post-metadata">

**Author:** ![brit-alexis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@brit-alexis](https://forum.wixstudio.com/u/brit-alexis)\
**Post date:** [July 14, 2019, 4:12am UTC](https://forum.wixstudio.com/t/onitemready-not-working-solved/17479/14 "2019-07-14T04:12:13Z")

</div>

@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:

```javascript
$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!

![](https://us1.discourse-cdn.com/wix/original/3X/3/6/3640ea62ac4a18993c552e47f72b32b54139959c.gif)
