web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum

Test if someone did an input?

(0) ShareShare
ReportReport
Posted on by

Hey guys,

do you know, how to test, if somebody gives in some new values?

Like here in my page, I have created a row with some data.

Then I created with the transferfields-function a copy in another page. So that I have the most of the values in that other page to do some calculations.

I am doing this with an action.

Now I want to create new data in the below page, but the new values do not appear in the second page.

How can I achieve this?

In the OnValidate-trigger of the first field in my page/table? To test, if someone did an input.

pastedimage1567599965817v1.png

Thank you :)

Categories:
I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Not so clear: If the TRANSFERFIELDS to the other page (table) is done via an action (menu button), you need to call that action from the newly inserted record. Otherwise you should start transferfields from a trigger like OnModify or so on).

  • Suggested answer
    Peter Zentner Profile Picture
    390 on at

    You can achieve that in a couple different ways. If you want to make sure that the field in the other table is updated as soon as the value is entered, you can create some code in the OnValidate trigger for each field:

    if "Field Name" <> xRec."Field Name" then begin

     OtherTable.Get(PrimaryKey);

     OtherTable."Field Name" := "Field Name";

     OtherTable.Modify(true);

    end;

    However, if there are any errors thrown on the table you are entering information in, you will still have the new values in the other table, so that is not the best solution.

    You could, in the OnModify trigger, also do the same tests as above for each field and then assign the field value to the other table. Or you could check, if any of a list of fields is changed and then do a transferfields again:

    if ("Field 1" <> xRec."Field 1") or ("Field 2" <> xRec."Field 2") … then begin

     OtherTable.Get(PrimaryKey);

     OtherTable.TransferFields(Rec);

     OtherTable.Modify(true);

    end;

    You will obviously have to replace the field names with your field names, use the proper primary key, and create a variable for the other table.

  • Community Member Profile Picture
    on at

    Thank you for your responses ;)

    Maybe it is good to write a function, which I call in the OnInsert and OnDelete triggers, because also deleted lines should be deleted in the other page.

    Do you know some standard code in NAV, where something like this is done?

    Maybe this makes it more clear:

    Imagine I create a new sales line and that one is automatically duplicated to a posted sales invoice.

    And if I delete a sales line, the associated line in posted sales invoices is deleted.

    So something like this is my goal.

  • Peter Zentner Profile Picture
    390 on at

    You can look at Customers or Sales Headers for the delete portion of it at least. You basically would add code in the OnDelete trigger of the table to filter for any records in the other table and then do a DeleteAll().

    I can't think of anything in standard that would synchronize tables, since typically, you try not to have duplicate information in different tables that have to be synchronized. However, if you truly want to synchronize the data, you can focus in the OnInsert, OnModify, OnDelete, and OnRename triggers of the table.

    If you don't allow changes to any fields in the "other table", you can do something like this:

    OnInsert trigger:

    if not OtherTable.Get(PrimaryKey) then begin

     OtherTable.TransferFields(Table);

     OtherTable.Insert();

    end else begin

     OtherTable.TransferFields(Table);

     OtherTable.Modify();

    end;

    OnModify trigger:

    Same code as above. So you can create a function that does the part above and call the function from both triggers.

    OnDelete trigger:

    if OtherTable.Get(PrimaryKey) then

     OtherTable.Delete();

    OnRename trigger:

    if OtherTable.Get(oldprimarykeyvalues) then

     OtherTable.Rename(new values for primary key);

  • Community Member Profile Picture
    on at

    Now I did it in that way:

    Function.PNG

    I call my function in the OnInsert-trigger with Rec.

    In the function I give as a parameter the line, which I want to insert.

    As variables I have the header and line of the second table/page and the header of the line, which I want to insert.

    I make a Setrange to find the right header of the seconf table/page.

    If there is a line, I want to insert in the other one, I create a new line in the second one and so on.

    Unfortunately it is not working...

    Do you have an idea?

    When I insert a new line in my first table/page, nothing happens...

  • Peter Zentner Profile Picture
    390 on at

    It is a bit difficult to see, but what I am seeing is that you do a SetRange on the Line using the ProtocolHeader.Code. But the Header is not part of the parameters of your Insert_Items_From function. So, the "Code" is always empty in the ProtocolHeader and therefore, you are filtering on lines with an empty code and it probably doesn't find anything.

    You probably want to do this

    Line.SetRange(Code, Line.Code);

  • Community Member Profile Picture
    on at

    Thank you for your advice ;)

    I changed my code now in that way:

    Lot.PNG

    And it works more or less, because when I give in the data in the first table "Line", only the first value I gave in appears in the second table "ProtocolLine".

    So after leaving the first field in the first table, the record is suddenly inserted...why starts the insert after leaving the first field and not after leaving the complete row?

    I am calling my function in the OnInsert-trigger...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans