# How to disable button with grid is not empty condition?

**URL:** <https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368>\
**Category:** Developer Forum\
**Created:** [September 29, 2017, 1:42pm UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368 "2017-09-29T13:42:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![smoch9339](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@smoch9339](https://www.dynamicsuser.net/u/smoch9339)\
**Post date:** [September 29, 2017, 1:42pm UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/1 "2017-09-29T13:42:26Z")

</div>

hello guys

I have form called TmpPurchReqTable form and in my form they want me to inactive of Purpose button when My form’s gird is empty.Normally I have a select button and it brings filtered data when I click it,but If I dont click my form’s grid is empty.

How can I can check the grid’s condition to disable a button?

this is my purpose button method:

while select TmpPurchReq where AxsTmpPurchReq.AxsAddProp == NoYes::Yes  
{

\_PurchPropItemTemplate.clear();  
\_PurchPropItemTemplate.initFromtmpPurchReq(TmpPurchReq);  
\_PurchPropItemTemplate.AxsPurchPropID = \_PurchPropTable.PurchPropID;  
\_PurchRequestLine = AxsTmpPurchReq.PurchRequestline(true);  
\_PurchRequestLine.AxsPurchPropID = \_PurchPropTable.PurchPropID;  
\_PurchRequestLine.AxsPropStatus = PropStatus::Approval;  
\_PurchRequestLine.BuzItemDesc = TmpPurchReq.BuzItemDesc;

\_PurchRequestLine.update();  
\_PurchPropItemTemplate.insert();  
}

ttscommit;

info(strfmt(’%1 ’ + ‘@AXS3406’,\_PurchPropTable.PurchPropID));  
ttsbegin;

delete\_from TmpPurchReq;

ttscommit;

---

<div class="post-metadata">

**Author:** ![smoch9339](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@smoch9339](https://www.dynamicsuser.net/u/smoch9339)\
**Post date:** [September 29, 2017, 3:26pm UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/2 "2017-09-29T15:26:20Z")

</div>

public int active()  
{  
TmpPurchReq \_TmpPurchReq;

int ret;  
;

ret = super();  
if(\_AxsTmpPurchReq.axsPurchRequestID)  
{  
button.enabled(true);  
ELEMENT.setdata();  
}  
else  
{  
button.enabled(false);  
}  
return ret;  
}  
I wrote somethingl like that for diasbale the the button ,but of course Its not working

My froms is tmp form and I dont know how to check grid is empty of not.Grid comes with value only I push the se select button and in select button there is code to fill the temp form  
could you guys help me please

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [September 29, 2017, 3:59pm UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/3 "2017-09-29T15:59:25Z")

</div>

Have you tried by setting NeedsRecord property on button to Yes?

---

<div class="post-metadata">

**Author:** ![smoch9339](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@smoch9339](https://www.dynamicsuser.net/u/smoch9339)\
**Post date:** [October 2, 2017, 8:22am UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/4 "2017-10-02T08:22:55Z")

</div>

I checked the button’s properties but could not see it.

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [October 2, 2017, 8:35am UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/5 "2017-10-02T08:35:28Z")

</div>

![Property.PNG](https://us1.discourse-cdn.com/flex023/uploads/dugusers/original/2X/e/e438334e9a26eb8d29ba77bf11e2ac2510bd304c.png)

---

<div class="post-metadata">

**Author:** ![smoch9339](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@smoch9339](https://www.dynamicsuser.net/u/smoch9339)\
**Post date:** [October 2, 2017, 8:41am UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/6 "2017-10-02T08:41:32Z")

</div>

![Screenshot_10.png](https://us1.discourse-cdn.com/flex023/uploads/dugusers/original/2X/d/daa43aae4d30ab520642dccf161844852faec65e.png) it is ax 2009,Maybe there is no noorecords on ax 2009?

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [October 2, 2017, 8:59am UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/7 "2017-10-02T08:59:41Z")

</div>

That property exists in AX 2012. You have tagged your post under AX 2012.  
There is no such property in AX 2009, you have to write code.  
In active method of the data source,  
button.enabled(dataSource.RecId);

---

<div class="post-metadata">

**Author:** ![smoch9339](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@smoch9339](https://www.dynamicsuser.net/u/smoch9339)\
**Post date:** [October 2, 2017, 9:04am UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/8 "2017-10-02T09:04:03Z")

</div>

Isorry about the wrong tagged,I did not check the ax version at first.

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [October 2, 2017, 9:07am UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/9 "2017-10-02T09:07:33Z")

</div>

That’s fine. Have you tired with the code in active method?

---

<div class="post-metadata">

**Author:** ![smoch9339](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@smoch9339](https://www.dynamicsuser.net/u/smoch9339)\
**Post date:** [October 2, 2017, 9:15am UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/10 "2017-10-02T09:15:20Z")

</div>

I tried it ,my form 's datasource table is temp table.so when I first open its empty if I pusht the select button its getting value by query from another table but they want before pushing the select button they want to dis able to purpose button.cuz if the forms empty its creating empty requestlines they dont want this.so I am trying to diasable the purpose button if the temp table’s form is empty

---

<div class="post-metadata">

**Author:** ![smoch9339](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@smoch9339](https://www.dynamicsuser.net/u/smoch9339)\
**Post date:** [October 2, 2017, 9:16am UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/11 "2017-10-02T09:16:45Z")

</div>

button.enabled(dataSource.RecId); ı tried this ,but did not work  
public int active()  
{

int ret;  
;

ret = super();

Purpose.enabled(TmpPurchReq.RecId);

return ret;  
}

---

<div class="post-metadata">

**Author:** ![smoch9339](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@smoch9339](https://www.dynamicsuser.net/u/smoch9339)\
**Post date:** [October 2, 2017, 9:41am UTC](https://www.dynamicsuser.net/t/how-to-disable-button-with-grid-is-not-empty-condition/64368/12 "2017-10-02T09:41:57Z")

</div>

I figured out I wrote your code select button it worked
