Add a record to a custom table on a form

Hello,

We want to store some additional data for a sales order header. So, we added a custom table with SalesId as the primary key.

We modified the SalesTable form and added a new tab for the custom fields. The custom table fields are not mandatory. So, we used the outer-join relationship.

When we try to create a record in the custom table, we get the error “Field SalesId must be filled in.” The error occurs in validateWrite method. We tried initializing the SalesId in initValue, create, and write methods. But, we are still getting the error.

Where should we initialize the SalesId to prevent this error?

Thanks.

On validateWrite try to create a record on your table and refresh dataSource of jour table

It doesn’t have to be outer join. You can use the delayed.
Which table’s validatewrite it is calling?

The custom table’s datasource

Is the custom table in one2one relationship with SalesTable? If yes then you can create a record when the Sales record is created and use innerjoin to update fields later. This way there will always be one record with each salesId.

If you don’t require one2one then I suppose you are using a action pane to insert a new record in the customTable? or how is it initializing? Anyway you can initialize the SalesId in the write method of the datasource method before calling super().

Thank you to all of you for your responses. The problem was that the relationship between the SalesTable and the custom table wasn’t setup properly. Once I set that up, everything worked like a charm.