Populate subform based on header selection

DnealDneal Member Posts: 103
Hi All,

I need to have the No. in the sales invoice details populate based on the sell-to-customer in the header. So when the user selects a sell to customer the No. field auto populates.(it will be auto populating based on a field I added to the customer table.)

I'm having trouble with triggers and how to get this to display once the selection is made.

Any tips or ideas would be greatly appreciated.

Thanks,
Dneal

Comments

  • fufikkfufikk Member Posts: 104
    I'd propably start with the onValidate trigger in the header table on the sell-to-customer field.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    I've been messing with this for some years ago. Don;t remember exactly how I got it to work. Basicly what happend was that someone added the customer field to the primary key so that is was popupated automaticaly. We changed it back to the orriginal key and got it to work via other triggers. You don;t want to change navision;s keys. O:)

    A friend of me asked the same question last week. I'll ask if he got it to work.
  • DenSterDenSter Member Posts: 8,305
    The header table has a function called 'UpdateLines' or something like that. Add your custom field to the function and call it from the OnValidate trigger in the Header table.
  • DnealDneal Member Posts: 103
    Thanks for your response. My issue is I can't get the value to display in the subform after the selection has been made in the header. I must be missing something very simple here. Please help.

    Dneal
  • DenSterDenSter Member Posts: 8,305
    Try CurrForm.UPDATE; in the OnAfterValidate trigger of the header field.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Sorry, I seem to have missread your post. I thougt you wanted to have access to the customer no. when entering a new salesline.
  • DnealDneal Member Posts: 103
    Hi Again all,

    Thanks for all the replies. This is what has happened.

    I have the following code put in the OnTimer() trigger of the sales details.

    IF Customer.GET(xRec."Sell-to Customer No.") THEN BEGIN
    "No." := Customer."Default Account";
    CurrForm.UPDATE;
    END;

    I'm not even sure if this is a good idea to do.
    But what is happening now is that the only time the NO. field updates in the sales details is when a No. has been selected in the sales details AND I reselect the Sell-to Customer No.

    Why doesn't it show right away?

    Dneal
  • DenSterDenSter Member Posts: 8,305
    No never put any data related code on any form. All of your field validation code should be in the table or in functions elsewhere. Only use any form triggers to display related code. You don't want to use the timer event either, because that refreshes the form and will save the information when you may not be ready to save it yet.

    Then the next issue is your use of xRec, why are you using xRec and not Rec?

    What do you want to do? When you select a sell-to customer in the Invoice header, you want something on the line to automatically be entered? What do you want to enter automatically? What are the conditions under which this happens? Is this a default value on the Customer Card? There are plenty of field validations in the Sales Header validation that flow through to the line detail that you can take a look at, like Location Code for instance.
  • DnealDneal Member Posts: 103
    Thank you for information.

    This is what needs to happen.
    To reduce data entry for the customer we have defaulted some of the values in the sales invoice details. The Type is to = G/L Account, the quantity = 1 and the No = the G/L account number on the customer(On the Customer card is a new field that contains a G/L account number.

    When a new record is created I have this code on the OnNewRecord of the details subform:

    Type := xRec.Type::"G/L Account";
    Quantity := 1;

    I used xRec because the existing code was using xRec.(I made the assumption I should use it, and just kept using it. :oops: )

    When a sales invoice is created and the user selects the Sell-To Customer and they want to see the G/L account number for the customer to appear in the existing No. field of the subform. Here is where I'm running into issues. It would even be acceptable if the user were to click or tab over the type field. But I'm having issues with getting this to display as well.

    I really would appreciate some guidance here. I apologize for my lack of understanding of the triggers.

    Dneal
Sign In or Register to comment.