save data in new table

Also why do you use xRec? That means that you are getting the dates for the previous line, not the line you are in.

What exactly do you mean with change the primary key in table 50012? I have test now defined as primarty key

You have not done that no.
Because I can see that you have still not added the two news fields to the table (Item No. and BOM Line No), as I wrote in the reply above.

And without these two fields defined in the table, then you cannot add them to the primary table.

And you should really consider contacting a partner, or get a little more training in NAV development before you continue. Like learning the basics about creating tables, fields, keys etc… I mean like learning specify a new primary key, that’s normally almost the first you would start with. [;)]

[Y]

Do you mean that it works now or? I guess not, as you have STILL NOT added the two fields to the table. You refer to the ones in the Stuklijst table instead…

Oke,

I have it now like this:



BeginDate - OnAfterValidate()
ItemAddition.SetDates(xRec,ItemAddition.BeginDate,ItemAddition.EndDate);

and this:



EndDate - OnValidate()
  ItemAddition.SetDates(xRec,ItemAddition.BeginDate,ItemAddition.EndDate);

and this:


Documentation()

Form - OnInit()

Form - OnOpenForm()

Form - OnCloseForm()

Form - OnQueryCloseForm() : Boolean

Form - OnActivateForm()

Form - OnDeactivateForm()

Form - OnFindRecord(Which : Text[1024]) : Boolean

Form - OnNextRecord(Steps : Integer) : Integer

Form - OnAfterGetRecord()

Form - OnAfterGetCurrRecord()
//ItemAddition.SetDates(xRec,ItemAddition.BeginDate,ItemAddition.EndDate);

Form - OnBeforePutRecord()

Form - OnNewRecord(BelowxRec : Boolean)

Form - OnInsertRecord(BelowxRec : Boolean) : Boolean
ItemAddition.GetDates(Rec,ItemAddition.BeginDate,ItemAddition.EndDate);


Form - OnModifyRecord() : Boolean

Form - OnDeleteRecord() : Boolean

Form - OnTimer()

Form - OnCreateHyperlink(VAR URL : Text[1024])

Form - OnHyperlink(URL : Text[1024])

SetRecFilters()

InputDateStart := ItemAddition.BeginDate;
InputDateEnd := ItemAddition.EndDate;

{

  IF (TODAY >=  ItemAddition.BeginDate) AND (TODAY <=  ItemAddition.EndDate) THEN BEGIN
    RecSalesHeaderQuote.FncCheckBOM('affoni');
  END;
 }
{
IF StartingDateFilter <> '' THEN
  SETFILTER("Starting Date",ItemAddition.BeginDate, StartingDateFilter);
ELSE
  SETRANGE("Starting Date");
 }

But it overwrites every new record. I get this as output:

timestamp	test	BeginDate	EndDate	Subscription	No_	Item No_	BOM Line No_
0x00000002BC6CEBCF		2016-02-02 00:00:00.000	2016-02-02 00:00:00.000				

But the problem is that if I do this:


IF GET(BOM."Parent Item No.",BOM."Line No.") THEN BEGIN
  StartDate := BeginDate;
  EndDate := EndDate;
END

I still get the warning that Too many key fields were specified.

And I added now the extra fields:

Enabled	Field No.	Field Name	Data Type	Length	Description
Yes	1	test	Text	30	
Yes	2	BeginDate	Date		
Yes	3	EndDate	Date		
Yes	4	Subscription	Text	100	
Yes	5	No.	Code	20	
Yes	6	Item No.	Text	30	
Yes	7	BOM Line No.	Text	30	

Sorry, but I give up… [:’(]

Why? I understand the problem now. It is here in:


IF BOM.SETRANGE(BOM."Parent Item No.",BOM."Line No.") THEN BEGIN
  StartDate := BeginDate;
  EndDate := EndDate;
END

So I changed to setrange. But now there is a type conversie: code to int

I try it like this:


IF BOM.FINDFIRST THEN BEGIN
     EVALUATE(VarInteger,BOM."Parent Item No.");
     BOM.SETRANGE(BOM."Parent Item No.", VarInteger);
END;

Because ,BOM."Parent Item No. is a varchar and BOM."Line No. is a integer

Hi Erik,

ok, I understand that that the primary keys from table 50012 has to be the same as the primary keys of the other table.

I have set the primary keys of table 50012 the correct way:

and I have to code like this:


IF GET(BOM."Parent Item No.",BOM."Line No.") THEN BEGIN
  StartDate := BeginDate;
  EndDate := EndDate;
END

But I still get an error when I want to add a item - To many keys where specified:

ToManyPrimaryFields.png

Open View–>Keys and check how many keys are there in first line

Oke, by keys I have it like this: Enabled Key SumIndexFields

Yes Parent Item No.,Item No. But the problem now is that if I add an item. every time the item dates overwrites the old dates. So I only see one row in the table 50012:

timestamp	test	BeginDate	EndDate	No_	Item No_	Parent Item No_
0x00000002BC770E4F		2016-02-01 00:00:00.000	2018-02-01 00:00:00.000		0	

And this is the setDates method:


SetDates(BOM : Record "BOM Component";VAR StartDate : Date;VAR EndDate : Date)
// Called from OnValidate of start and end dates in form 36
Stuklijst."Parent Item No." := BOM."Parent Item No.";
Stuklijst."Line No." := BOM."Line No.";
StartDate := StartDate;
EndDate := EndDate;

IF NOT MODIFY THEN 
  INSERT;

as per the code it will update the existing line only.
if you would like to add each time new line for modification then you need to have one more field like Line no. and change the code accordingly.

and for startdate and enddate trigger on the form 36 I have this:


BeginDate - OnAfterValidate()
ItemAddition.SetDates(xRec,ItemAddition.BeginDate,ItemAddition.EndDate);

yes, ok. But there are some strange things.

for example I do this:


BOM.INIT;
"Item No." := 60;
"Parent Item No." := BOM."Parent Item No.";
Stuklijst."Line No." := BOM."Line No.";
StartDate := StartDate;
EndDate := EndDate;

IF NOT MODIFY THEN 
  INSERT;

and I add an item like this:

and I go to the database, then I see the record:

timestamp	test	BeginDate	EndDate	No_	Item No_	Parent Item No_
0x00000002BC770EFB		2016-02-01 00:00:00.000	2016-02-01 00:00:00.000		0	
0x00000002BC77107C		2016-02-01 00:00:00.000	2016-08-02 00:00:00.000		0	610014
0x00000002BC7710A8		2016-05-02 00:00:00.000	2016-05-05 00:00:00.000		50	610014
0x00000002BC7710C6		2018-05-02 00:00:00.000	2016-08-08 00:00:00.000		60	610014

but If I go back to the Items, the record is gone. like this:

So in either way. It seem that table 90 doens’t join table 50012 - otherwise the recod from table 50012 would be visible in form 36, that makes use of table 90.

So What I have to change? Thank you

So It seems it is doing an insert. But it doesnt show the date values in Navision.

This is what I have now for the get method:


IF BOM.GET("Parent Item No.",BOM."Line No.") THEN BEGIN
  IF  BOM.FINDFIRST THEN;
  "Item No." := BOM."Line No.";
  MESSAGE('hallo');

 //BOM.SETFILTER(BOM."Line No.","Item No.");
//IF GET(BOM."Line No.", "Item No.") THEN BEGIN
  StartDate := BeginDate;
  EndDate := EndDate;
  MESSAGE('hallo');
END

so can anybody help me? So the data is committed to the database. But how to show the data? Thank you