# Hide/Show Button based on the Dataset Field within a Collection (Dynamic Page)

**URL:** <https://forum.wixstudio.com/t/hide-show-button-based-on-the-dataset-field-within-a-collection-dynamic-page/75262>\
**Category:** Ask the community\
**Tags:** code\
**Created:** [November 29, 2025, 10:52pm UTC](https://forum.wixstudio.com/t/hide-show-button-based-on-the-dataset-field-within-a-collection-dynamic-page/75262 "2025-11-29T22:52:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mary\_Cobbina](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mary_cobbina/32/100867_2.png) [@Mary\_Cobbina](https://forum.wixstudio.com/u/Mary_Cobbina)\
**Post date:** [November 29, 2025, 10:52pm UTC](https://forum.wixstudio.com/t/hide-show-button-based-on-the-dataset-field-within-a-collection-dynamic-page/75262/1 "2025-11-29T22:52:54Z")

</div>

Hello,

I am getting an error message with custom css on button.

I have created two buttons on a page using custom code to hide one button if the dataset field in my collection is set to “SOLD” and to show the other button if the dataset field in the same collection is set to “BUY” or “RENT”. Both buttons are linked to a pop-up form.

It doesn’t work. This is the error message:

UserError: datasetApi ‘getCurrentItem’ operation failed  
Caused by DatasetError: Operation (getCurrentItem) is not allowed because the field used to build this page’s URL is empty

Here is the code:

$w.onReady( **function** () {

// Wait for the dataset to be ready

$w(‘#dataset1’).onReady(() =\> {

// Get the current item from the dataset

**const** item = $w(‘#dataset1’).getCurrentItem();

// Check if the Availability field is “SOLD”

**if** (item && item.Availability && item.Availability.toUpperCase() === “SOLD”) {

$w(‘#button39’).hide();

} **else** {

$w(‘#button39’).show();

}

// Check if the Availability field is “BUY” or “RENT”

**if** (item && item.Availability && (item.Availability.toUpperCase() === “BUY” || item.Availability.toUpperCase() === “RENT”)) {

$w(‘#button86’).hide();

} **else** {

$w(‘#button86’).show();

}

});

});

---

<div class="post-metadata">

**Author:** ![Baksheesh](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Baksheesh](https://forum.wixstudio.com/u/Baksheesh)\
**Post date:** [November 30, 2025, 4:34am UTC](https://forum.wixstudio.com/t/hide-show-button-based-on-the-dataset-field-within-a-collection-dynamic-page/75262/2 "2025-11-30T04:34:22Z")

</div>

> [@Mary\_Cobbina](#):
>
> UserError: datasetApi ‘getCurrentItem’ operation failed

UserError: datasetApi ‘getCurrentItem’ operation failed  
often happens on dynamic pages viewed in Preview mode but has no effect on the live site. If you’re getting this error on the live site, check to make sure that it is actually a dynamic page.

Try this:

```javascript
$w.onReady(function () {
  $w('#dataset1').onReady(() => {
    let item = $w('#dataset1').getCurrentItem();
    if (item && item.Availability) {
      const status = item.Availability.toUpperCase();

      if (status === "SOLD") {
        $w('#button39').hide();
      } else {
        $w('#button39').show();
      }

      if (status === "BUY" || status === "RENT") {
        $w('#button86').hide(); 
      } else {
        $w('#button86').show();
      }
    }
  });
});

```

---

<div class="post-metadata">

**Author:** ![Mary\_Cobbina](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mary_cobbina/32/100867_2.png) [@Mary\_Cobbina](https://forum.wixstudio.com/u/Mary_Cobbina)\
**Post date:** [November 30, 2025, 2:31pm UTC](https://forum.wixstudio.com/t/hide-show-button-based-on-the-dataset-field-within-a-collection-dynamic-page/75262/3 "2025-11-30T14:31:18Z")

</div>

> [@Baksheesh](#):
>
> ```javascript
> $w.onReady(function () {
> $w('#dataset1').onReady(() => {
> let item = $w('#dataset1').getCurrentItem();
> if (item && item.Availability) {
> const status = item.Availability.toUpperCase();
> 
> if (status === "SOLD") {
> $w('#button39').hide();
> } else {
> $w('#button39').show();
> }
> 
> if (status === "BUY" || status === "RENT") {
> $w('#button86').hide(); 
> } else {
> $w('#button86').show();
> }
> }
> });
> });
> 
> ```

Hello,

Thanks for your reply. I published the site, and it didn’t work.

I deleted my code and pasted your code, which is much simpler. However, that too didn’t work.

The page is definitely a Dynamic Page from a collection with all of our listings.

Do you know what could be the issue to fix it?

I appreciate your help.

Mary

---

<div class="post-metadata">

**Author:** ![Dan\_Suhr](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/dan_suhr/32/94074_2.png) [@Dan\_Suhr](https://forum.wixstudio.com/u/Dan_Suhr)\
**Post date:** [November 30, 2025, 10:22pm UTC](https://forum.wixstudio.com/t/hide-show-button-based-on-the-dataset-field-within-a-collection-dynamic-page/75262/4 "2025-11-30T22:22:25Z")

</div>

Dynamic pages are built from a URL field (slug) in your collection. I would check to make sure this field has values for all items. If one is blank you will get that error.

---

<div class="post-metadata">

**Author:** ![Baksheesh](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Baksheesh](https://forum.wixstudio.com/u/Baksheesh)\
**Post date:** [December 1, 2025, 4:36am UTC](https://forum.wixstudio.com/t/hide-show-button-based-on-the-dataset-field-within-a-collection-dynamic-page/75262/5 "2025-12-01T04:36:22Z")

</div>

you should confirm that the status (item.Availability) is actually being passed in the code by adding the line`console.log("Availability is: ", status")` after status is declared. If you’re not seeing BUY or SOLD in the logs, check the correct spelling of the field key - is it Availability or availability? If status is correct then check the logic to make sure the correct button is hiding/showing.

---

<div class="post-metadata">

**Author:** ![Mary\_Cobbina](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mary_cobbina/32/100867_2.png) [@Mary\_Cobbina](https://forum.wixstudio.com/u/Mary_Cobbina)\
**Post date:** [December 1, 2025, 12:38pm UTC](https://forum.wixstudio.com/t/hide-show-button-based-on-the-dataset-field-within-a-collection-dynamic-page/75262/8 "2025-12-01T12:38:50Z")

</div>

THANKS ALL. Resolved and working 🙂

There was a typo in the dataset.

Thanks for your help.
