Using this filter functionality in your code is something you'll definitely use at some point in time as a programmer.
Although it's possible to do it in a single line of code, I prefer a 3 step solution. That way it's more flexible.
Let me show you by example. We'll filter the customers records in form CustTable, only showing customers with currency USD.
Step 1: Declare a class variable
In the ClassDeclaration method of the form, define a range.
QueryBuildRange CurrencyQBR;
Step 2: Instantiate the new range.
In the init method on the datasource of the form, you assign the range to a specific field (after the super call).
public void init()
{
super();
CurrencyQBR = this.query().dataSourceName('CustTable').addRange(fieldnum(CustTable,Currency));
}
Step 3: In the last step, you assign a value to the range.
This is done in the executeQuery method on the same datasource of the form. Before the super call. Like this:
public void executeQuery()
{ ;
CurrencyQBR.value(queryvalue('USD'));
super();
}
You're done! When you open the form, your customer records are filtered, you only get the customers with currencycode USD set up.
Like I said in the intro of this post, this can be done in one line of code as well.
In the init method of the form datasource, after the super call, place this code:
this.query().dataSourceName('CustTable').addRange(fieldnum(CustTable,Currency)).value(queryvalue('USD'));
But this way, it's fixed. If you choose the 3 step method, you could for example use a variable in the range value. The way to go would be to place an input field on your form, get the value from it and supply it in the executeQuery method.
For example like this:
public void executeQuery()
{ ;
CurrencyQBR.value(queryvalue(MyInputField.text()));
super();
}
Just make sure the executeQuery method is executed, thus applying the desired filter (maybe be using a button on your form to activate it).
Of course it's possible to combine multiple querybuildranges.
Thanks! I have a question related to building queries on forms. I have a form with 2 datasources, say alpha and beta where beta is linked to alpha and alpha is the primary datasource. I have a button that opens a QueryRun object and builds a query from these two datasources (this is to allow users to not have to create their own custom query/filter). I can run it but it doesn't mark the datasource as being filtered. How might this be possible as I cannot use the alpha_ds.filter(...) method. Here is example code:
ReplyDeletevoid clicked()
{
Query q;
QueryBuildRange qbr;
QueryBuildDataSource qbds;
QueryBuildDataSource qbdsSearchFIeld;
QueryRun qr;
;
super();
q = alpha_ds.query();
qbds = q.dataSourceTable(tablenum(alpha));
qbds.clearRanges();
if (q.dataSourceTable(tablenum(beta)))
qbdsSearchField = q.dataSourceTable(tablenum(beta));
else
qbdsSearchField = qbds.addDataSource(tablenum(beta));
qbdsSearchField.relations(true);
if (qbdsSearchField.findRange(fieldnum(beta, SearchField)))
qbr = qbdsSearchField.findRange(fieldnum(beta, SearchField));
else
qbr = qbdsSearchField.addRange(fieldnum(beta, SearchField));
qr = new QueryRun(q);
if (qr.prompt())
{
alpha_ds.query(qr.query());
alpha_ds.executeQuery();
// this works to filter down but does not display the Remove Filter button
}
}
Great post.
ReplyDeleteThanks alot!!!
I'm using Dynamics AX 2009
ReplyDeleteI'll get in the following error in step3:
super() is not allowed here
what to do?
Extend your class in classDeclaration. Altough classes automatically extends RunBase it might help if you extend it manually.
ReplyDeleteHi 'Anonymous'!
ReplyDeleteMake sure you edit the executeQuery method of the datasource of the form. Don't add that method in step 3 as new method on the form.
Hi Willy,
ReplyDeleteThanks for posting this. However I'm not clear on how to create a button to activate the filter. Can you point me to the right direction please?
I've been trying for the past week going nowhere :) Thanks in advance.
Hello Hendro,
ReplyDeleteWhen you add a button, make sure you edit the clicked method of that button. Instead of calling super, make sure the executeQuery method of your datasource is called. This will trigger the applying of the filter. (Example: CustTable_ds.executeQuery())
Wonderful!
ReplyDeleteThank you so very much, it's working :)
Superb dude..
ReplyDeleteits working :)
This comment has been removed by a blog administrator.
ReplyDeleteHello there, I must warn you if you set range by code simply by "addRange" and want to allow user to set their own filters too (advanced, filter by value, etc.)
ReplyDeleteExample: If you use "addRange" to add filter on date column "1.1.2012..31.12.2012" by code, and that user will then use filter by value "1.4.2012", than there will be two ranges for the same columns in the background and only the last one of them will be applied !!! (check advance filter to see that - one is generated by code, one by user).
Try to use SysQuery::findOrCreateRange() to be sure that you will just change value in existing range rather than adding another one. You don't have to check for existing range because the system will do so.
Try to accommodate yourself with SysQuery class, this will prevent you from serious headache.
PS: I forgot to mention to be aware to addRange not from the method executeQuery on the datasource, but for example preparing the variables to change the range later from init method, ex. (AX2009 see the init methods on ForecastSales, ProjForecastEmpl, etc):
ReplyDeleteqB = this.query().dataSourceNo(1);
criteriaExpand_1 = qB.addRange(fieldnum(ForecastSales,ExpandId));
Thank you very much indeed. Clearly explained and bloody easy to do.
ReplyDeleteI just wanted to say that your blog is perhaps the most usefull source of AX info I've found.
ReplyDeleteThank you.
In the first example. What should you do when you want to see everything but the 'USD'?
ReplyDeletethx for helping!
Hi there. I'm trying to use a variation of this method on the query for the employee list page. My problem is, after setting the filter (I want the user to see only a subset of the employees, e.g. only the ones in the same department), the user can manually alter it afterwards. Is there some way of preventing this without completely removing the possibility of filtering for the user? Thx.
ReplyDeleteI suggest you have to add after addRange(fieldnum(...)).status(RangeStatus::Locked);
ReplyDeletegood nice
ReplyDeleteVery useful
ReplyDeleteNice post. You can visit following link to get Ax 2012 technical code and error solutions
ReplyDeleteAx 2012 Development and Coding
Very Useful for me as a beginner,Thanks
ReplyDeleteHello,
ReplyDeleteHere I understand that the range is for the Currency ,may be a string.
But suppose their is an Enum again which is an unbound control, that is to have a filter.Upon the change in the enum value...Grid in the form chenges repectively.
Hello,
ReplyDeletedo any one know how to filter the records in lookup by using from date and todate
Thank you.
ReplyDeleteThanks, very useful.
ReplyDeleteRegards
Yes, Its helped me, Nice dude :-)
ReplyDeletehi ,
ReplyDeletehow to get currentcompany details in form when opening form (form is listpage one).
Subscribe to learn this new technique in Ax
ReplyDeletehttps://youtu.be/8dXjRzSk910
Considerable article, We at Addhunters shifted this service to a level much higher than the broker concept. you can see more details like this article amlak
ReplyDeleteBatman
ReplyDeleteArdahan
Adıyaman
Antalya
Giresun
QWDX
Antalya
ReplyDeleteAntep
Burdur
Sakarya
istanbul
8ATT
elazığ
ReplyDeletebitlis
mardin
kastamonu
van
4YV
malatya evden eve nakliyat
ReplyDeleteartvin evden eve nakliyat
kocaeli evden eve nakliyat
ankara evden eve nakliyat
düzce evden eve nakliyat
RE478
https://istanbulolala.biz/
ReplyDeleteVHPYRF
yalova evden eve nakliyat
ReplyDeletetunceli evden eve nakliyat
giresun evden eve nakliyat
ağrı evden eve nakliyat
van evden eve nakliyat
FTV3X0
ığdır evden eve nakliyat
ReplyDeletebitlis evden eve nakliyat
batman evden eve nakliyat
rize evden eve nakliyat
niğde evden eve nakliyat
BQP1
86951
ReplyDeleteZonguldak Şehir İçi Nakliyat
Urfa Evden Eve Nakliyat
Urfa Parça Eşya Taşıma
Kilis Şehirler Arası Nakliyat
Mardin Parça Eşya Taşıma
Samsun Şehirler Arası Nakliyat
Batıkent Parke Ustası
Urfa Şehir İçi Nakliyat
Bursa Şehirler Arası Nakliyat
7AA85
ReplyDeleteKırşehir Evden Eve Nakliyat
peptides
Zonguldak Evden Eve Nakliyat
buy sustanon
buy clenbuterol
testosterone propionat for sale
Referans Kimliği Nedir
winstrol stanozolol for sale
halotestin for sale
B1CC7
ReplyDeleteSakarya Lojistik
Denizli Şehirler Arası Nakliyat
Düzce Lojistik
Bingöl Lojistik
Erzurum Şehir İçi Nakliyat
Muğla Evden Eve Nakliyat
Muğla Şehir İçi Nakliyat
trenbolone enanthate
Silivri Duşa Kabin Tamiri
3FE43
ReplyDeleteÇerkezköy Evden Eve Nakliyat
Kırıkkale Şehir İçi Nakliyat
Çerkezköy Sineklik
İstanbul Şehir İçi Nakliyat
Sivas Şehirler Arası Nakliyat
Kırklareli Evden Eve Nakliyat
Ünye Kurtarıcı
Bartın Şehir İçi Nakliyat
Iğdır Lojistik
C0D12
ReplyDeleteSincan Fayans Ustası
Çerkezköy Kombi Servisi
Bitrue Güvenilir mi
Binance Referans Kodu
Ankara Parke Ustası
Binance Referans Kodu
Tekirdağ Fayans Ustası
Referans Kimliği Nedir
Karapürçek Parke Ustası
9663A
ReplyDeleteÇerkezköy Ekspertiz
Konya Evden Eve Nakliyat
Mamak Boya Ustası
Osmaniye Evden Eve Nakliyat
Karapürçek Fayans Ustası
Coinex Güvenilir mi
Pursaklar Boya Ustası
Nevşehir Evden Eve Nakliyat
Bartın Evden Eve Nakliyat
A0059
ReplyDeleteEdirne Evden Eve Nakliyat
Çerkezköy Oto Lastik
Kalıcı Makyaj
Binance Referans Kodu
Lbank Güvenilir mi
Erzurum Evden Eve Nakliyat
Binance Referans Kodu
Binance Güvenilir mi
Ünye Petek Temizleme
98666
ReplyDeleteÜnye Oto Boya
Bitlis Evden Eve Nakliyat
Çerkezköy Marangoz
Referans Kimliği Nedir
Çerkezköy Sineklik
Ankara Asansör Tamiri
Burdur Evden Eve Nakliyat
Çankaya Fayans Ustası
Referans Kimliği Nedir
F42AD
ReplyDeleteBitcoin Nedir
Coin Madenciliği Nasıl Yapılır
https://resimlimag.net/
Kripto Para Nasıl Oynanır
Bitcoin Nasıl Para Kazanılır
Bitcoin Kazma Siteleri
Binance Kimin
Kripto Para Madenciliği Siteleri
Bitcoin Giriş Nasıl Yapılır
87627
ReplyDeleteCoin Nasıl Oynanır
Kripto Para Üretme Siteleri
Bitcoin Kazma Siteleri
Coin Nasıl Çıkarılır
Coin Kazanma
Kripto Para Nasıl Üretilir
Bitcoin Yatırımı Nasıl Yapılır
Binance Hangi Ülkenin
Bitcoin Kazanma
D8BB2
ReplyDeletehttps://e-amiclear.com/
87631
ReplyDeleteboostaro
cialis 100 mg
glucotrust official website
kamagra jel
cialis 20 mg satın al
cialis 5 mg
6C120
ReplyDeletetunceli mobil sohbet siteleri
sivas mobil sohbet odaları
canlı sohbet uygulamaları
ısparta Sesli Sohbet Odası
Adıyaman Canlı Sohbet Et
antalya en iyi görüntülü sohbet uygulaması
bilecik canlı sohbet ücretsiz
mersin sesli sohbet
edirne kadınlarla rastgele sohbet
9DBD3
ReplyDeleteBitcoin Nasıl Alınır
Binance Sahibi Kim
Mexc Borsası Kimin
Youtube İzlenme Hilesi
Bitcoin Nasıl Çıkarılır
Coin Nasıl Oynanır
Bone Coin Hangi Borsada
Twitter Takipçi Hilesi
Telegram Abone Hilesi
3BB78
ReplyDeletedexview
debank
pancakeswap
satoshivm
phantom wallet
pinksale
dappradar
shapeshift
thorchain
A94CF
ReplyDeletegate io
bitmex
canlı sohbet odaları
telegram kripto grupları
bitcoin hangi bankalarda var
bkex
binance
kucoin
probit
B6551
ReplyDeleteprobit
probit
https://toptansatinal.com/
referans kodu
mexc
kraken
kızlarla canlı sohbet
4g mobil proxy
türk kripto telegram grupları
77832
ReplyDeletebinance 100 dolar
paribu
probit
mexc
en iyi kripto grupları telegram
binance referans
binance referans kimliği
en iyi kripto para uygulaması
bitcoin hesabı nasıl açılır
80F59
ReplyDeletebinance 100 dolar
kaldıraç nasıl yapılır
bitexen
mobil 4g proxy
kripto para telegram grupları
kraken
canlı sohbet siteleri
kripto ne demek
kucoin
3A883
ReplyDeleteehliyet sınav soruları
sunucu
fuar standı
vds satın al
sanal sunucu
fiziksel sunucu
seo nedir
güneş paneli fiyatları
jeneratör fiyatları
1D155
ReplyDeleteMMORPG Oyunlar
İş İlanları
Facebook Sayfa
Telegram Kanal Satın Al
ehliyet sınav soruları
fuar standı
Google Adwords Kupon Satışı & Alışı
Hosting Firmaları
Sosyal Medya İşleri
7FB4B
ReplyDeleteYoutube SEO
anime önerileri
Wordpress Temaları
Instagram Beğeni Satın Al
Telegram Abone Satın Al
Silkroad Sunucu Kiralama
film önerileri
Youtube Beğeni Satın Al
Düşecek Domainler
BCFF8
ReplyDeletefilm önerileri
Youtube Abone Satın Al
seo danışmanı
Kurumsal Hosting
seo
Hosting Satın Al
Facebook Reklam Verme
Site Satışı
Satılık Adsense Hesabı
99329
ReplyDeleteFacebook Beğeni Satın Al
Wordpress Hosting
Toptan Ürünler
netflix dizi önerileri
Netflix Dizi Önerileri
Online Oyunlar
Mobil Uygulama Yapma
Google Harita & İşletme Kaydı
Sosyal Medya İşleri
1E538
ReplyDeleteAch Coin Yorum
Fil Coin Yorum
One Coin Yorum
Dash Coin Yorum
Orbs Coin Yorum
Gala Coin Yorum
Atom Coin Yorum
Bitcoin Forum
Dgb Coin Yorum
awerarefstgryrt
ReplyDeleteصيانة افران جدة
FDRGFHBT
ReplyDeleteصيانة افران بمكه
International Nursing Recruitment Agencies in the USA play a vital role in connecting healthcare facilities with skilled nurses from around the world. They simplify the complex recruitment process, managing credential verification, visa applications, and orientation programs to ensure seamless integration. With a focus on ethical practices, these agencies guarantee fair treatment and proper placement in reputable institutions. They also offer ongoing support, such as interview preparation and relocation assistance, to ensure a smooth transition for international nurses. Trust these agencies to efficiently bridge the gap between global nursing talent and the demands of the U.S. healthcare system.
ReplyDeletehttps://www.dynamichealthstaff.com/international-nursing-recruitment-agencies-in-usa
شركة كشف تسربات المياه بالاحساء gKaLSOZGrb
ReplyDelete