I need to define a global variable in a Table which is a boolean flag. When I copy fields from another table in a field validation I turn this flag on. In insert trigger I check this flag and if it is off some fields take default values. BUT this flag is always off. Why the global variable does not keeps its value in Insert trigger. How can I handle this situation ?
quote:
Originally posted by philipv
I need to define a global variable in a Table which is a boolean flag. When I copy fields from another table in a field validation I turn this flag on. In insert trigger I check this flag and if it is off some fields take default values. BUT this flag is always off. Why the global variable does not keeps its value in Insert trigger. How can I handle this situation ?
Forgive the stupid question - are you sure the trigger is executed? Anna
quote:
Originally posted by Anna Perotti
quote:
Originally posted by philipv
I need to define a global variable in a Table which is a boolean flag. When I copy fields from another table in a field validation I turn this flag on. In insert trigger I check this flag and if it is off some fields take default values. BUT this flag is always off. Why the global variable does not keeps its value in Insert trigger. How can I handle this situation ?
Forgive the stupid question - are you sure the trigger is executed? Anna
Yes I am
Hi Philip, are you sure that you are using the same variable for copying fields and INSERT. Or do you use a RESET before INSERT. Both leads to clearing all global variables. Br Josef Metz
Here is the code : Equipment No. - OnValidate() IF Type=Type::A THEN BEGIN EquipLine.GET(…); VALIDATE(“Is Standard”,EquipLine.“Is Standard”); VALIDATE(“Basic Price”,EquipLine.“Basic Price”); VALIDATE(Markup,EquipLine.Markup); VALIDATE(“Final Price”,EquipLine.“Final Price”); VALIDATE(ETT,EquipLine.ETT); CopyFlag:=TRUE; END; OnInsert() IF NOT CopyFlag THEN BEGIN IF VMgtSetup.GET THEN Markup:=VehicleMgtSetup.MarkUp; END ELSE CopyFlag:=FALSE;
Hi Philip, how do you call the OnValidate and the INSERT br Josef Metz
quote:
Originally posted by jm
Hi Philip, how do you call the OnValidate and the INSERT br Josef Metz
They are called during form data entry
The only solution that works in this case is to define a temporary table with this flag and accessing the flag from this table. But then what the purpose of global variables ? What globals they are if their values implicity initialized in every trigger ? [:(]
Hey have you checked, that you have not define a local variable which you have named the same like the global variable? Fred
quote:
Originally posted by FredBergmann
Hey have you checked, that you have not define a local variable which you have named the same like the global variable? Fred
Sure yes. Make just a test a table and try it.
Your problem is that you are looking at two variables…The Rec from the Form and the Rec from the Table (The Table gets the Flag set, but the Form is Inserted [}:)]). Some of the easier options might include creating CopyFlag as a field on the table, or creating a function to set copyflag on the Insert Trigger of the table.
Have you tried using the same triggers and a global in the form? I know, that it is better to work in the tables, but in such a situation this should work. Greetings, Frank
quote:
Originally posted by FPulsfort
Have you tried using the same triggers and a global in the form? I know, that it is better to work in the tables, but in such a situation this should work. Greetings, Frank
Thanks Frank. This seems to work but I prefer to keep the code in table and handle this with temporary table.
quote:
Originally posted by philipv Thanks Frank. This seems to work but I prefer to keep the code in table and handle this with temporary table.
In your case you’re having several options: 1) Create a field on the table instead of using a variable. 2) Create the function on the form. 3) Adding a function on the oninsert trigger that checks if it’s copied in a different way (like checking on insert if it’s having any value on the field you’re validating and it’s type A then it’s copied) (example: IF ((“Equipment No.” <>‘’) AND (Type = Type::A)) THEN Copyflag := true; ) The problem is that the form won’t keep the value on the variable as it will just “refresh” getting the variable all time.
The scope of globals is not that global then you would like. In cases like this I use Additional field. It’s the most straightforward. You already have added few fileds one boolean more is not big deal. Maybe you can even tell by some other field that the this OnValidate has been run, for example “Basic Price”<>0.
Just a question Field named “Type” are a menber of the primary Key?
Another way to go: Use a SingleInstance Codeunit. Only catch here is that users can open the same form twice, so you need some version checking.