Unique bool on table
carioka
Member Posts: 20
Hi
I have a bool into a table and wanted the bool could only be marked in a single row of the table
I think this:
bool onvalidate()
thistable.RESET;
thistable.SETFILTER(thistable.Dietas,'Yes');
IF thistable.FINDFIRST THEN
thistable.bool := FALSE;
but this dont run... !!! HELP !!
I have a bool into a table and wanted the bool could only be marked in a single row of the table
I think this:
bool onvalidate()
thistable.RESET;
thistable.SETFILTER(thistable.Dietas,'Yes');
IF thistable.FINDFIRST THEN
thistable.bool := FALSE;
but this dont run... !!! HELP !!
0
Comments
-
Sorry, my code is:
bool onvalidate()
thistable.RESET;
thistable.SETFILTER(thistable.bool,'Yes');
IF thistable.FINDFIRST THEN
thistable.bool := FALSE;0 -
if i understood correct,u want to set bool true for only one row and if already exists in any row,u want to false that.
am i right?:-k0 -
mohana_cse06 wrote:if i understood correct,u want to set bool true for only one row and if already exists in any row,u want to false that.
am i right?:-k
Yes, if you change the bool TRUE... another row change the bool false...
Sorry for my english
Now, i think on this function:
REPEAT
IF pT_Dimension.Dietas = TRUE THEN
pT_Dimension.Dietas := FALSE;
UNTIL pT_Dimension.NEXT = 0;0 -
After the change, you need to call .MODIFY to store the modification into DB... ;-)
But:
1) If you are filtering to boolean, do not use string, use TRUE or FALSE isntead, and use SETRANGE instead SETFILTER (this is source of your problem, that the NAV is showing error about data type). Your code will not work under another language...
2) You are changing field, on which you are filtering - it have impact to performance and behaviour of the loop. Search for more info about this problem...0 -
kine wrote:After the change, you need to call .MODIFY to store the modification into DB... ;-)
But:
1) If you are filtering to boolean, do not use string, use TRUE or FALSE isntead, and use SETRANGE instead SETFILTER (this is source of your problem, that the NAV is showing error about data type). Your code will not work under another language...
2) You are changing field, on which you are filtering - it have impact to performance and behaviour of the loop. Search for more info about this problem...
I filter by SETRANGE but the problem even there0 -
If your table isn't too big, you could easily do this the following way : Take a second variable of the same recordtype, select all records in the table EXCEPT the current one, then do a modifyall( boolean,false) on them0
-
I'm not sure what you're trying to do.
If you try to only have one row at each given time to have 1 or 0 rows a true value then you could try thisbool onvalidate() IF bool then BEGIN //check if the new bool value is true or not thistable.SETFILTER("primary key field", '<>%1',rec."primary key field"); thistable.SETRANGE(bool,true); //will skip all the records that have false, good for performance if thistable.find('-') then thistable.modifyall(bool,false); end;
which I now realise is the same answer as MBerger above0 -
you can try like this also.
bool onvalidate() IF Bool THEN BEGIN thistable.SETRANGE(Bool,TRUE); IF thistable.FIND('-') THEN thistable.Bool := FALSE; CurrForm.Bool.UPDATE; thistable.MODIFY; END ELSE;0 -
mohana_cse06 wrote:you can try like this also.
bool onvalidate() IF Bool THEN BEGIN thistable.SETRANGE(Bool,TRUE); IF thistable.FIND('-') THEN thistable.Bool := FALSE; CurrForm.Bool.UPDATE; thistable.MODIFY; END ELSE;
This code dont run because on the table dont have CurrForm :S0 -
carioka wrote:mohana_cse06 wrote:you can try like this also.
bool onvalidate() IF Bool THEN BEGIN thistable.SETRANGE(Bool,TRUE); IF thistable.FIND('-') THEN thistable.Bool := FALSE; CurrForm.Bool.UPDATE; thistable.MODIFY; END ELSE;
This code dont run because on the table dont have CurrForm :S
hey sory,i have tried this on form.
u can try without that line in table but i think the table wont update until you close it and open :-k0 -
mohana_cse06 wrote:carioka wrote:mohana_cse06 wrote:you can try like this also.
bool onvalidate() IF Bool THEN BEGIN thistable.SETRANGE(Bool,TRUE); IF thistable.FIND('-') THEN thistable.Bool := FALSE; CurrForm.Bool.UPDATE; thistable.MODIFY; END ELSE;
This code dont run because on the table dont have CurrForm :S
hey sory,i have tried this on form.
u can try without that line in table but i think the table wont update until you close it and open :-k
there is no way to update the table in real time ??0 -
Have you tried the first code?0
-
It just LOOKS like the table is not updated until you open and close.
The visual information is out of date.
You can refresh the table by: clicking on the lines, or opening and closing the table.
But better is to use a form: you can use statements like CurrForm.UPDATE to refresh the visual information.0 -
The FIND is not needed if using MODIFYALL.There are no bugs - only undocumented features.0
-
yes,if u want to do this by form, my code works perfectly.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 333 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

