I have been fighting with this for a week or so now in what little time I can devote to sorting it out… I am rewriting a (simpler than servoy’s) crm for a client. There are currently 5 tables: contacts, line_items, sale_data, service_data and stock_data. In (form) contacts there is a “new sale” button. Click it and you are taken to (form) sale_data, in which details of contact have been supplied to a new record. There is also a portal linking to table line_items. When you create a new record it populates a new sale_data record with the contacts details, and creates a new line in the portal to which it adds a unique id and allows you to add description, price etc. My “new sale” method is as follows:
var contactid = contactsid
sale_count = sale_count + 1
var salecount = sale_count
contacts_to_sale_data.newRecord()
forms.sale_data.controller.show()
forms.sale_data.controller.find()
forms.sale_data.clientid = contactid
forms.sale_data.sale_count = salecount
forms.sale_data.controller.search()
forms.sale_data.sale_data_to_line_items.newRecord()
The point is that it is supposed to increment the sale_count for each contact (Bob jones has had 24 “sales” (which can be translated into quotes or invoices)) it then copies bob jones’ contact id (with the variable declaration) and the incremented sale_count and creates this new record. Switches to sale_data and does a search on the ONE unique record that it has just created (there will always be only one relating to contact_id and sale count.) Once found, you are able to add line items to the portal which adds records to line_items table.
It works a treat… mostly
every so often (a lot) I get a “java.lang.nullpointerexception” error - once it happens once it happens over and over and over until I try muckin about with it. Then it works again for a bit.
I cannot figure out with the debugger where it is failing although it may be that it is not remembering the var contactid = contactsid and var salecount = sale_count. These seem when it fails to not get populated into the relevant fields as they should before the search. I have tried changing the final line to a portal add record but that stops it working all together.
I don’t know where else to turn as every small advance I make on this seems to fail miserably. I discovered that I had two identical relationships
one of which wasn’t allowed to create related records. I assumed that this “MUST BE IT” because it was using one of the relationships some of the time (when it was working) and the other relationship when it wasn’t. Didn’t make a dot of difference (although a Eureka was heard when it worked for a bit - as usual). I also saw that sale_count and contactsid were undefined - named em and… no joy…
So, anyone else had a problem like this? It would be so much better if it didn’t work some of the time. That way I would have something substantial to get my teeth into. as it is, it sometimes works and I HATE that…
Thanks