Web Connection
Logical fields are losing there original value when saving a related business object
Gravatar is a globally recognized avatar based on your email address. Logical fields are losing there original value when saving a related business object
  Chris Jewell
  All
  Jun 19, 2019 @ 05:23am

Hi folks,

I've nearly finished my first Web Connect (WC) App, but I've spotted an issue with my App that I'm struggling to understand. I'll try and explain, I have created a business object (BO) that reflect a specific table, the user is then shown some of the data in a web page, which they can edit and then save. At this point, no errors are reported and the changes are saved, except all logical fields have been set to false. I ran some tests and I was able to isolate the problem to the following line of code:

poError.Errors = Request.UnbindFormVars(oPOFileBus.oData)

For example oPOFileBus.oData.Shipped shows as true, before the above line is executed, but immediately after it is false. All non-logical fields seem to be ok, it only seems to be logical fields that are affected, any ideas? If you need more details please let me know?

******* Amendment ******* I have dug a bit deeper and I believe it is the code below which is within the wwrequest.prg file. Does anyone know why logical fields are not included in this check? The logical fields are not on the form, so ideally I would like it to loop, but I'm reluctant to edit the core WC code.

IF lcType # "L" AND !THIS.IsFormVar(lcFormVar)

LOOP

ENDIF

Regards, Chris

Gravatar is a globally recognized avatar based on your email address. re: Logical fields are losing there original value when saving a related business object
  Rick Strahl
  Chris Jewell
  Jun 19, 2019 @ 01:04pm

Logical values are always a problem in Web applications because checkboxes don't post back if they are unchecked. This means you can't check for whether the value was set or is just not there - it produces the same thing.

The only way around that is to make 100% sure that you always display the proper value for a check box from the model originally. If they are not part of your display values, then you either need to explicitly exclude that field using lcExcludedProperties from binding, or you need to put a hidden form variable on the form that provides the original value.

The code you point out specifically deals with logical values in the model that's unbound - anything but logicals check to see if a matching control can be found. But that doesn't work reliably with Checkboxes for the reason mentioned above.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Logical fields are losing there original value when saving a related business object
  Chris Jewell
  Rick Strahl
  Jun 20, 2019 @ 04:02am

Thanks Rick, I understand. I have written a function to pass the unused logical fields to the 'UnBindFormVars' function and that has worked, so thank you for explaining. Regards, Chris

© 1996-2019