or, if you loop through a table where the Names are stored and you want in these table set the boolean "isrightname", then u can use also this:
MyTable.setcurrentkey(YourNeededKey);
MyTable.setrange("Needed Field","NeededValue");
if MyTable.findset(true) then begin
repeat
if (Strlen(MyTable.FieldToCheck) >=2) then begin //Uppercase,Lowercase
MyTable.isrightname := (MyTable.FieldToCheck[1] in [72,104]) and (MyTable.FieldToCheck[2] in [65,97]);
MyTable.modify;
//also possible is to use a string function like strpos()
end;
until MyTable.next = 0;
end;
if you will set it only on a variable on the form, and u diesn't save the variable value, u can use:
isrightname := (FieldToCheck[1] in [72,104]) and (FieldToCheck[2] in [65,97]);
or
MyTableasVariable.setrange(PromaryKeyField,PrimarykeyOftheRecFromtheCard);
MyTableasVariable.setfilter("FieldToCheck",'%1','Ha*') ; //also possible with the @ infront if the Ha
isrightname := not MyTableasVariable.isempty;
Thank you guys for that interesting solutions. i never thought that i have to redevelop half NAV to just get this simple Filter in the text field.
But many of you advised SETFILTER. Well, let me shortly explain what i want to do and than i think you know that SETFILTER is just not really possible.
I use NAV 2009 RTC, the contact list. I have set a style to the name column (so all the names in the list are styled green.) But i dont want that all names are green, i only want names green that starts with "Hans". So there is a StyleExpr field, where you can set a boolean expression. In MSDN i read that i ofcourse cant just write in that field "Name = 'Hans*'". I have to set a global boolean variable and in the function "OnAfterGetRecord" i have to evaluate every single name and find out whether it starts with hans. If so i have to set this global variable to true, otherwise to false. and this global variable i can use in StyleExpr. So SETFILTER is not helpfull for me.
All this works when i write isrightname := Name = 'Hans Viller';
But than only Hans Viller is styled. But i need all Hanses... :-)
Thank you guys for that interesting solutions. i never thought that i have to redevelop half NAV to just get this simple Filter in the text field.
But many of you advised SETFILTER. Well, let me shortly explain what i want to do and than i think you know that SETFILTER is just not really possible.
I use NAV 2009 RTC, the contact list. I have set a style to the name column (so all the names in the list are styled green.) But i dont want that all names are green, i only want names green that starts with "Hans". So there is a StyleExpr field, where you can set a boolean expression. In MSDN i read that i ofcourse cant just write in that field "Name = 'Hans*'". I have to set a global boolean variable and in the function "OnAfterGetRecord" i have to evaluate every single name and find out whether it starts with hans. If so i have to set this global variable to true, otherwise to false. and this global variable i can use in StyleExpr. So SETFILTER is not helpfull for me.
All this works when i write isrightname := Name = 'Hans Viller';
But than only Hans Viller is styled. But i need all Hanses... :-)
My solution is quick - you just enter one line into temporary table and see if the value is inside your filter. This will return you the TRUE-FALSE you need. If you create function for that, you can use it in OnAfterFormat trigger to know if you need to color the name or not. Where is problem? ;-)
this way you could make Fritz green too instead of only Hans.
also what you match could be longer
leave out the lowercase function calls if you need to match case
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
if you will set it only on a variable on the form, and u diesn't save the variable value, u can use: or
Regards
The first modify: Mytable.modifyall(IsRightname,true) ; <-- u modify all recs in the table
MyTable.setfilter("Needed Field",'@%1*','Ha') ; <-- i mean i must be: MyTable.setfilter("Needed Field",'%1','@Ha*') ;
;-)
Regards
But many of you advised SETFILTER. Well, let me shortly explain what i want to do and than i think you know that SETFILTER is just not really possible.
I use NAV 2009 RTC, the contact list. I have set a style to the name column (so all the names in the list are styled green.) But i dont want that all names are green, i only want names green that starts with "Hans". So there is a StyleExpr field, where you can set a boolean expression. In MSDN i read that i ofcourse cant just write in that field "Name = 'Hans*'". I have to set a global boolean variable and in the function "OnAfterGetRecord" i have to evaluate every single name and find out whether it starts with hans. If so i have to set this global variable to true, otherwise to false. and this global variable i can use in StyleExpr. So SETFILTER is not helpfull for me.
All this works when i write isrightname := Name = 'Hans Viller';
But than only Hans Viller is styled. But i need all Hanses... :-)
My solution is quick - you just enter one line into temporary table and see if the value is inside your filter. This will return you the TRUE-FALSE you need. If you create function for that, you can use it in OnAfterFormat trigger to know if you need to color the name or not. Where is problem? ;-)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
It is simple... :whistle:
That's true that in this case no more is needed. My example was originally for more complex filters...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Thank you guys.
also what you match could be longer
leave out the lowercase function calls if you need to match case
DoesStartWith(startswith : Text[10];Name : Text[30]) : Boolean
exit(lowercase(copystr(name,1,strlen(startswith))) = lowercase(startswith));
Steve