mibuso.com

Microsoft Business Solutions online community
It is currently Thu Aug 21, 2014 6:02 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [Solved] filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 6:14 pm 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
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

Code: Select all
VendTable.SETFILTER(VendTable."Search Name",'%1%2',VendName,'*');

-->failed


Top
 Profile E-mail  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 6:18 pm 
Offline

Joined: Fri May 18, 2012 3:04 pm
Posts: 148
Location: Armenia, Quindio
Country: Colombia (co)
Code: Select all
VendTable.SETFILTER(VendTable."Search Name",'%1%2',COPYSTR(VendName1,5),'*');

_________________
Gerry Kistler
KCP Consultores


Top
 Profile E-mail  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 6:22 pm 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
gerrykistler wrote:
Code: Select all
VendTable.SETFILTER(VendTable."Search Name",'%1%2',COPYSTR(VendName1,5),'*');


failed also

my complete code
Code: Select all
          VendName := COPYSTR(FORMAT(COPYSTR(vString,1,PosCode-1)),1,5);
          VendTable.RESET;
          VendTable.SETFILTER(VendTable."Search Name",'%1%2',VendName,'*');
          IF VendTable.FIND('-') THEN


Top
 Profile E-mail  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 6:31 pm 
Offline

Joined: Mon May 18, 2009 6:36 am
Posts: 824
Location: India
Country: India (in)
Code: Select all
VendTable.SETFILTER(VendTable."Search Name",'%1','@'+VendName+'*');

_________________
Vijay Gupta
Changing the code is last step. Try to change processes first...


Top
 Profile E-mail  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 6:37 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Fri Jun 06, 2003 9:01 pm
Posts: 7061
Location: L.I., New York
Country: United States (us)
COPYSTR(VendName1,5)
Should be
COPYSTR(VendName,1,5)

_________________
Harry Ruiz
http://www.BiloBeauty.com
http://www.autismspeaks.org


Top
 Profile E-mail WWW  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 6:39 pm 
Offline

Joined: Fri May 18, 2012 3:04 pm
Posts: 148
Location: Armenia, Quindio
Country: Colombia (co)
That's what I get for typing the code here rather than in NAV first, then copy and paste.

_________________
Gerry Kistler
KCP Consultores


Top
 Profile E-mail  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 6:55 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Fri Jun 06, 2003 9:01 pm
Posts: 7061
Location: L.I., New York
Country: United States (us)
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? :-k

_________________
Harry Ruiz
http://www.BiloBeauty.com
http://www.autismspeaks.org


Top
 Profile E-mail WWW  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 7:04 pm 
Offline

Joined: Fri May 18, 2012 3:04 pm
Posts: 148
Location: Armenia, Quindio
Country: Colombia (co)
I see now it is the %1%2 which is the problem. Try this:
Code: Select all
      VendTable.SETFILTER(VendTable."Search Name",'%1',VendName + '*');

_________________
Gerry Kistler
KCP Consultores


Top
 Profile E-mail  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 9:00 pm 
Offline
MVP Microsoft Dynamics NAV
NAV TechDays 2014 attendee

Joined: Thu Oct 16, 2003 8:50 am
Posts: 12439
Location: Brno
Country: Czech Republic (cz)
and what about
Code: Select all
VendTable.SETFILTER(VendTable."Search Name",'%1*',VendName);
... ;-)

_________________
Kamil Sacek
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.


Top
 Profile E-mail WWW  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 9:04 pm 
Offline

Joined: Fri May 18, 2012 3:04 pm
Posts: 148
Location: Armenia, Quindio
Country: Colombia (co)
Of course, fewer characters so much improved. :D

_________________
Gerry Kistler
KCP Consultores


Top
 Profile E-mail  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 9:20 pm 
Offline
MVP Microsoft Dynamics NAV
NAV TechDays 2014 attendee

Joined: Thu Oct 16, 2003 8:50 am
Posts: 12439
Location: Brno
Country: Czech Republic (cz)
No, but correct usage of parameters... ;-)

_________________
Kamil Sacek
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.


Top
 Profile E-mail WWW  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Mon Jun 04, 2012 9:45 pm 
Offline

Joined: Fri May 18, 2012 3:04 pm
Posts: 148
Location: Armenia, Quindio
Country: Colombia (co)
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 Consultores


Top
 Profile E-mail  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Tue Jun 05, 2012 4:20 am 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
if i use it's ok, but it should have the exact name
Code: Select all
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 code
Code: Select all
VendTable.SETFILTER(VendTable."Search Name",'%1',VendName + '*');

or
Code: Select all
VendTable.SETFILTER(VendTable."Search Name",'%1*',VendName);


the error message as i attach


Attachments:
Error.jpg
Error.jpg [ 14.44 KiB | Viewed 931 times ]
Top
 Profile E-mail  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Tue Jun 05, 2012 6:21 am 
Online
MVP Microsoft Dynamics NAV

Joined: Tue Sep 02, 2008 8:37 am
Posts: 4590
Location: Hyderabad
Country: India (in)
The error message attached is nothing to do with suggested code..its a setup error..
activate debugger and check..

_________________
-Mohana
http://mibuso.com/blogs/mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav


Top
 Profile  
 
 Post subject: Re: filter using first 5 characters (C/AL Code)
PostPosted: Tue Jun 05, 2012 6:24 am 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
Hi All,
it works
Code: Select all
VendTable.SETFILTER(VendTable."Search Name",'%1',VendName + '*');


use this code
thanks


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: