# How to remove range from form data source by Code

**URL:** <https://www.dynamicsuser.net/t/how-to-remove-range-from-form-data-source-by-code/46453>\
**Category:** Developer Forum\
**Created:** [June 11, 2013, 10:20am UTC](https://www.dynamicsuser.net/t/how-to-remove-range-from-form-data-source-by-code/46453 "2013-06-11T10:20:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahemaan](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@shahemaan](https://www.dynamicsuser.net/u/shahemaan)\
**Post date:** [June 11, 2013, 10:20am UTC](https://www.dynamicsuser.net/t/how-to-remove-range-from-form-data-source-by-code/46453/1 "2013-06-11T10:20:40Z")

</div>

Hi,

Just wondering if someone can help me please. I have designed a form with three data sources.

InventDim,InventSum,InventSum1.

I have applied a range on InventSum and InventSum1 data source to only display those items are in stock.

there in another check box when user hit that check box it call a method from class and display only those items which are out of stock from main warehouse. thats all working fine except a small bit when we un tick that check box it doesn’t clear that range and still shows filtered data . I have tried InventSum\_DS.reread refresh method but no result.

 ![5008.Capture.JPG](https://us1.discourse-cdn.com/flex023/uploads/dugusers/original/1X/9c09a1ece6fc2bb64c2da1244b458f5fe2dffcd3.jpeg)

I will appreciate any help in due course.

Kind Regards,

---

<div class="post-metadata">

**Author:** ![ThomasP](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@ThomasP](https://www.dynamicsuser.net/u/ThomasP)\
**Post date:** [June 11, 2013, 10:36am UTC](https://www.dynamicsuser.net/t/how-to-remove-range-from-form-data-source-by-code/46453/2 "2013-06-11T10:36:34Z")

</div>

Hi,

Did you try the following when untick your checkBox :

this.Query().datasourceNo(1).clearRanges();

yourDatasource\_ds.executeQuery() ; or yourDataSource\_ds.research(true);

let me know if it works for you

Regards,

Thomas

---

<div class="post-metadata">

**Author:** ![shahemaan](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@shahemaan](https://www.dynamicsuser.net/u/shahemaan)\
**Post date:** [June 11, 2013, 12:07pm UTC](https://www.dynamicsuser.net/t/how-to-remove-range-from-form-data-source-by-code/46453/3 "2013-06-11T12:07:24Z")

</div>

Hi Thomas ,

Thanks for you reply . this.query().dataSourceNo(1).ClearRanges() work though but not in my case this is my code behind check box .

public void clicked()

{

Container C;

Int i;

JS\_WareHouseInvent WH = new JS\_WareHouseInvent();

;

super();

if (Enf.value() == 1)

{

startLengthyOperation();

C = WH.OInENF(InventSum.inventDimId);

for (i = 0; i \<= ConLen(C);i++)

{

InventSum\_DS.query().dataSourceTable(tablenum(InventSum)).addRange(fieldnum(InventSum,ItemID)).value(SysQuery::value(conPeek(c,i)));

}

EndLengthyOperation();

}

else if (ENf.value() == 0)

{

InventSum\_Ds.query().dataSourceName(‘InventSum’).clearRanges();

}

InventSum\_Ds.executeQuery();

}

and datasource excute query

public void executeQuery()

{

showAvailable.value(strfmt(’((OnOrder != %1) || (PhysicalInvent != %2) || (Availphysical != %3) || (AvailOrdered != %4) || (Ordered != %5))’,

0,0,0,0,0));

Super()

}

so if i use that clearRanges() ; it throw me a compiler error as i have one more filter in execute query method which is suppose to be there all the time. How ever if i do not call that range then it is ok .

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [June 11, 2013, 12:14pm UTC](https://www.dynamicsuser.net/t/how-to-remove-range-from-form-data-source-by-code/46453/4 "2013-06-11T12:14:23Z")

</div>

You can simply use _clearRange()_ instead of _clearRanges()_. If a class offers one useful operation, it’s always useful to check whether there isn’t more useful stuff.

Another approach is to leave the range in place and change its value to _SysQuery::valueUnlimited()_.

---

<div class="post-metadata">

**Author:** ![shahemaan](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@shahemaan](https://www.dynamicsuser.net/u/shahemaan)\
**Post date:** [June 11, 2013, 12:28pm UTC](https://www.dynamicsuser.net/t/how-to-remove-range-from-form-data-source-by-code/46453/5 "2013-06-11T12:28:04Z")

</div>

Hi Guys,

Issue resolved here is my code

public void clicked()

{

Container C;

Int i;

JS\_WareHouseInvent WH = new JS\_WareHouseInvent();

;

super();

if (Enf.value() == 1)

{

startLengthyOperation();

C = WH.OInENF(InventSum.inventDimId);

for (i = 0; i \<= ConLen(C);i++)

{

InventSum\_DS.query().dataSourceTable(tablenum(InventSum)).addRange(fieldnum(InventSum,ItemID)).value(SysQuery::value(conPeek(c,i)));

}

EndLengthyOperation();

}

else if (ENf.value() == 0)

{

InventSum\_Ds.query().dataSourceName(‘InventSum’).clearRanges();

InventSum\_Ds.init();

}

InventSum\_Ds.executeQuery();

}

all i am doing is that i am calling init method once again after clearing the ranges and it is removing the second filter leaving the first one in place.

Many Thanks,
