Where do key fields get filled in on new subform rows

imurphyimurphy Member Posts: 308
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

  • SavatageSavatage Member Posts: 7,142
    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 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.
  • kapamaroukapamarou Member Posts: 1,152
    I think the fields are filled automatically, getting the data from the link of the subform to the parent form.

    What I would do would be to place my code on the OnInsert trigger of the Sales Line table.
  • imurphyimurphy Member Posts: 308
    If certain fields are automatically inserted from the header row - where is this specified that this takes place?

    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
  • SavatageSavatage Member Posts: 7,142
    probably better way of explaining it than me but
    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.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    imurphy wrote:
    If certain fields are automatically inserted from the header row - where is this specified that this takes place?

    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
    AutoSplitKey
    

    2/ To add additional data to the record go to the table and find the
    OnInsert
    
    trigger.

    8><
    ooops I had this open too long, I see Harry already answered.
    David Singleton
  • kinekine Member Posts: 12,562
    There is one generic rule: if some field which is part of primary key is filtered to single value in the form, it will be automatically populated when new line is created in the form. If you want to populate in same way another field, you need to enable PopulateAllFields property on the form. After that, any field filtered to one single value will be populated automatically. This works for all forms...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • imurphyimurphy Member Posts: 308
    Thanks for the info guys.

    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
  • kinekine Member Posts: 12,562
    It is why NAV is good for "Rapid" customizations. Many things are done without line of code... :-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.