filter using first 5 characters (C/AL Code)

julkifli33
Member Posts: 1,092
hi all
usually when we want to filter using '*'
but how to do that in CAL code?
let say we have vendor name : microsoftdynamics
but i just have parameter micro
how to filter using first 5 characters?
thanks
usually when we want to filter using '*'
but how to do that in CAL code?
let say we have vendor name : microsoftdynamics
but i just have parameter micro
how to filter using first 5 characters?
thanks
VendTable.SETFILTER(VendTable."Search Name",'%1%2',VendName,'*');-->failed
0
Answers
-
VendTable.SETFILTER(VendTable."Search Name",'%1%2',COPYSTR(VendName1,5),'*');
Gerry Kistler
KCP Consultores0 -
gerrykistler wrote:
VendTable.SETFILTER(VendTable."Search Name",'%1%2',COPYSTR(VendName1,5),'*');
failed also
my complete codeVendName := COPYSTR(FORMAT(COPYSTR(vString,1,PosCode-1)),1,5); VendTable.RESET; VendTable.SETFILTER(VendTable."Search Name",'%1%2',VendName,'*'); IF VendTable.FIND('-') THEN
0 -
VendTable.SETFILTER(VendTable."Search Name",'%1','@'+VendName+'*');
0 -
COPYSTR(VendName1,5)
Should be
COPYSTR(VendName,1,5)0 -
That's what I get for typing the code here rather than in NAV first, then copy and paste.Gerry Kistler
KCP Consultores0 -
How you you want to specify the first 5 digits?
Do you want a TEXTBOX where you enter 5 characters & then it filters?
Do you want to click on a name and it takes "that" name - get's the first 5 characters and then filters for others with the same starting 5?
Not sure what your final goal is? :-k0 -
I see now it is the %1%2 which is the problem. Try this:
VendTable.SETFILTER(VendTable."Search Name",'%1',VendName + '*');
Gerry Kistler
KCP Consultores0 -
and what about
VendTable.SETFILTER(VendTable."Search Name",'%1*',VendName);
... ;-)0 -
Of course, fewer characters so much improved.Gerry Kistler
KCP Consultores0 -
-
Yes, 6 fewer keystrokes. Both are correct and work but your's is preferred for less code space.
Note for the OP (julkifli33) - next time give your code sample along with the question, as your question was somewhat misleading as to the issue. Also any error message you received such as "No vendor found in the filter '%1%2'". You will get your answers sooner.Gerry Kistler
KCP Consultores0 -
if i use it's ok, but it should have the exact name
VendTable.SETRANGE(VendTable."Search Name",VendName);
because i want to import for 3rd party
even the same vendor, but i think its better if i search from the first 5 characters
because this 3rd party dont have vendor id
i use this codeVendTable.SETFILTER(VendTable."Search Name",'%1',VendName + '*');
orVendTable.SETFILTER(VendTable."Search Name",'%1*',VendName);
the error message as i attach0 -
The error message attached is nothing to do with suggested code..its a setup error..
activate debugger and check..0 -
Hi All,
it worksVendTable.SETFILTER(VendTable."Search Name",'%1',VendName + '*');
use this code
thanks0 -
Offtopic:VendTable.SETFILTER(VendTable."Search Name",'@%1*',VendName);
Guys, what's wrong on using the SETFILTER correctly? Filter in second parameter, values, in rest... do not forget that 3rd, 4th... parameters are strongly typed based on the field type. Second parameter is there to create filter with placeholders for values. I know, that there are sometime problems with the placeholders not replaced with the values, but it is just exceptional behavior and could be solved in exceptional way.
Sorry for this offtopic post, but I can't resist...
(same for MESSAGE(FORMAT(something)) instead MESSAGE('%1',something))0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions