Form/Subform

Is it pssible to access the global variable defined in a subform from the main form? I have a boolean ‘LineChanged’ defined as a global var in the subform. I will set this to TRUE if any field in any of the records in the subform is changed by the user. From the main form when the user leaves the sales order, I need to give a message if the value in LineChanged is TRUE. Pari.

No, it are actually two different forms which do not share common variables. However, you can call a function in the subform from the main form, so if you create a function there that returns the value of the boolean, you have your check. Be aware of the variety of situations you can have with lines in a subform (inserted, modified, deleted, or all at the same time. Only the manual changed fields or the system calculated ones also, etc.) Might lead to some complicated logic and a lot of work. John

Another option, is to just create a boolean field in the table of the sub form, then a flow field in the main form. Then you can

calcfields

if there is a value, reset the values in the sub table, and then give your message. It is a bit messey, and you also need to look at mulit user table licking etc. _________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________

quote:


Originally posted by John Tegelaar: No, it are actually two different forms which do not share common variables. However, you can call a function in the subform from the main form, so if you create a function there that returns the value of the boolean, you have your check. Be aware of the variety of situations you can have with lines in a subform (inserted, modified, deleted, or all at the same time. Only the manual changed fields or the system calculated ones also, etc.) Might lead to some complicated logic and a lot of work. John


I like the use of a function to access a variable defined in a subform. I tried it but does not work. Here is what I did: I defined the function in the subform with just an exit statement and under the Locals for the function defined a return value as LineChanged of type Boolean. This LineChanged is also defined as a global variable in the subform. In the main form I call the subform function as: currForm.SubformName.FORM.FunctionName IF LineChanged THEN MESSAGE(‘Load has not been posted. Quantities for the Order will be reset’); In the main form LineChanged is a global variable of type Boolean. Please advise. Thanks. Pari.

Try: IF currForm.SubformName.FORM.FunctionName THEN MESSAGE(‘Load has not been posted. Quantities for the Order will be reset’); Chris Krantz NCSD,NCSQL,MCSD,MCSE Microforum Inc. Toronto, Ontario, Canada

It won’t work this way. What you need to do is define a variable in the sub form, and set it on exiting the form, then create a function that returns the value of that variable. But in any case, it does apear that what you are doing should be a function of the table, not the form. Thus it should be possible (logically) to set the value in the sub-form source table, then reference it from the main form source table. Something like in sub form table

  
SubTable.LineChanged := true;
modify;

From the main table


calcfields(LineChangedInSubTable);
if LineChangedInSubTable then
  MESSAGE('Load has not been posted. Quantities for the Order will be reset');

_________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________

quote:


Originally posted by David Singleton: It won’t work this way. What you need to do is define a variable in the sub form, and set it on exiting the form, then create a function that returns the value of that variable. But in any case, it does apear that what you are doing should be a function of the table, not the form. Thus it should be possible (logically) to set the value in the sub-form source table, then reference it from the main form source table. Something like in sub form table

  
SubTable.LineChanged := true;
modify;

From the main table


calcfields(LineChangedInSubTable);
if LineChangedInSubTable then
  MESSAGE('Load has not been posted. Quantities for the Order will be reset');

_________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________


I tried what Chris suggested: IF currForm.SubformName.FORM.FunctionName THEN MESSAGE(‘Load has not been posted. Quantities for the Order will be reset’); It does not work. I have been trying to avoid creating fields in the header and line tables just for the purpose of coding. If nothing else works I guess I need to do it. Does anyone have any other suggestions? Thanks. Pari.

Don’t be concerned about creating new field, that is what Navision is designed for. By putting functional code in your forms, you are only going to create a nightmare for your pending upgrade (everyone upgrades eventually)(well almost). Create the new fields, it will make your life a lot easier in the future. _________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________

Thanks David. Pari.

I know that in the early days of Navision Programming, most people ask “why not put code in the forms” the answer is upgrades. I guess the first programming assignment that every new Navision Programmer should tackle is to upgrade a badly modified Navision install. When I started in Navision they did not have code on forms, so we didn’t have the option (except the statistics forms of course). So the problem never arose. Now days I always recommend people if you cna put it in the table put it there. Tables are the easiest part of the upgrade. By the way another tip, never use a navision field for something it was not designed for, create a new field, even if you ahve to add more code it will be less work at the next upgrade. _________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________

David: Thanks for your help. I tried adding a boolean field in the line table and a boolean flow field to the header table and setup the calc formula to Lookup to the field in the line table with the filter as Doc Type and Doc No.(Sales Order Header and Line tables) It seems to work only if all my lines have changed in the line table. I need the header table field to turn to TRUE even if one of the lines have changed. Pari.

Just check the formula, try using

IF Exists...

_________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________

quote:


Originally posted by David Singleton: Just check the formula, try using

IF Exists...

_________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________


If I use Exist, it sets the flowfield to TRUE all the time whether the field in the Line table is true or not for any of the lines.

You will need to create a new key which includes the “LineChanged” field at the end. Then make this one of the filters in the Exist formula. _________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________ Edited by - David Singleton on 2001 Sep 18 18:17:28

Here, try this: download PS (WW1 2.60b) _________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________ Edited by - David Singleton on 2001 Sep 18 18:31:01

quote:


Originally posted by David Singletondownload: Here, try this: PS (WW1 2.60b) _________________________ David Singleton Navision Consultant since 1991 <u


Thanks David. I will take a look. But I tried what you suggested earlier, that is include the LineChanged field in the flowfield filter and it seems to work(without adding to the key). Pari.

glad to see you have a solution. _________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________