Hi,
I have added some code at the table level modified Field and if the field is getting updated I am updating the value of another field based on the field value. This field is present at the same form level and the data source is different. I am able to update the value and view it after the page is refreshed however my question is how do I view the value immediately at the form level. I am aware I can do this by formDataSource.reread() and formDataSource.refresh() at the form level, however isn’t the same possible at the table level where I am calling the code.
The design is wrong. You’re updating database in modified(), which happens before the record is saved - and it may never be saved. That would leave your data in inconsistent state. I elaborated this topic in my blog post modifiedField() and database consistency.
Please make sure you fix this bug first.
Then you can either refresh data from your form (after calling the update at the table), or you can get a reference to the form data source from the table. For example:
FormDataSource formDs = FormDataUtil::getFormDataSource(this);
if (formDs)
{
formDs.reread();
formDs.refresh();
}
What exactly you should do depends on your specific situation, which you didn’t explain to us.
Hi, Thanks for your reply. Yes I have checked in my system however it is important to include my this piece of code in validate field (changed from modified field). When the records is already present and I am using this code it works fine however when it is a new record and I am updating the related field of another table it does not get included. Could you please help me understand some other approach which can be followed for this scenario?
Also the field is not getting immediately at form level when using the below at data source level of validate field method
FormDataSource formDs = FormDataUtil::getFormDataSource(this);
if (formDs)
{
formDs.reread();
formDs.refresh();
}
Updating data during validation is a deadly sin! I suggest you stop writing code and explain the business requirement to us. Then we can discuss a solution that won’t corrupt data in your client’s ERP system.
Also, don’t expect me to comment on your code that you didn’t show to me. For example, I don’t even know for which table you’re trying to call the refresh.
Hi Martin,
My requirement is: to do some external validation on tax exempt number field at the form VendTable, this validation needs to be invoked prior to the system validation which takes place at validate write hence I am writing the code at the validate write method of the table. In case it is a valid value then the known as field in the form needs to be updated which is coming from DirPartyTable with the reply from the external system.
Then run the validation logic (but not the update!) in validateWrite().
Run the update in insert()/update() methods of the table. That makes sure that both tables are updated in the same database transaction and therefore are either committed or rolled back togother, keeping the data consistent in both cases.