This is probably a really basic question to those of you with more experience. I'm trying to work out where I can insert a line of code so that it will be executed after a new line is inserted on a subform.
On a form with a subform (lets use a sales order form as an example), when you add a row to the subform the keyfields with the document type and number are inserted into the new rows fields.
I want to insert a value into a particular column of every new row on row insert.... but I'm sitting here scratching my head trying to work out where this is occuring.
I was expecting to find something like OnNewRow event on the subform which would do something like
newsalesline.document type := salesheaderline.document type
newsalesline.no := salesheaderline.document no
where I would add my line
newsalesline.newfield := DefaultValueBasedOnWhatsInTheSalesHeader
but I can't find it! So, I assume theres some sort of magic going on under the hood I'm not aware of. I've excluded it occuring in the table code as it would seem to be impossible.
Anyone able to shine some light on this process?
Thanks in advance
Ian
Comments
I think you answered your own question.
The key fields get automatically inserted.
Anyway, what field do you want to have updated on insert?
You can add your code to the sales line table OnInsert Trigger.
http://www.BiloBeauty.com
http://www.autismspeaks.org
What I would do would be to place my code on the OnInsert trigger of the Sales Line table.
I have just tried out what you suggested and it works fine - I was obviously looking for something more complicated it needed to be.
However now my curiosity is piqued - how does this bit of magic work on subform line insertion? Where does it get the key fields from? Something has to be saying 'create a new line with the same keyfields as this parent record', or 'when you create a new line, this is the record where the key fields come from'.
Ian
I see a Subform link to get the doc no.
I see onvalidate of type getting a function called getsalesheader
the autosplitkey increments the line no.
etc.
http://www.BiloBeauty.com
http://www.autismspeaks.org
There are two separate issues here and you need to address them seperately.
1/ The population of the key fields is handled in the sub form by the property
2/ To add additional data to the record go to the table and find the trigger.
8><
ooops I had this open too long, I see Harry already answered.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
While I'm not trying to solve any problem at the moment, its certainly good to know how this works. Several of us we were sitting in front of my screen yesterday trying to work out how this took place and we were all stumped. While intuitively we expected to find an explicit bit of code to do the key filling it was obvious that code wasn't there and we couldn't see anything in the relation form-subform which said which keyfields should be used to auto-fill... if indeed it did autofill. Knowing Nav it had to be done this way.
Ian
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.