Hi there,
I am trying to create a new record in another table when a new record is created in the item table. The table in question needs to use the newly created item number on insert and change as the primary key.
So, the code that I used was:
Form - OnInsertRecord(BelowxRec : Boolean) : Boolean
Blocked:= TRUE;
"Reordering Policy":= "Reordering Policy"::"Maximum Qty.";
LCHeader.INIT;
LCHeader."No.":="No.";
LCHeader."Item No." := "No.";
LCHeader.INSERT;
Unfortunately, I am guessing that as the item no has not been created, it is picking up a blank item number. Could you please tell me where the code should really sit to enable me to pick up the item number once the item no. has been created?
Many thanks,
Mike
0
Comments
Secondly why would you use two field to hold the same value?
LCHeader."No.":="No.";
LCHeader."Item No." := "No.";
What's the key of the LCHeader table?
You could on insert of the item table check to see if the item already exists on whatever your LCtable is. If it exists then MODIFY, If it doesn't then INSERT
http://www.BiloBeauty.com
http://www.autismspeaks.org
I have placed my code on the OnInsert part of the Item Card but now I am stuck on 2 issues:
1) I know for certain that the LCTable will not be manually filled in so the issue of there already being one is not a problem, BUT a usr may wish to change the Item no. from A0001 to A001A etc. How am I able to change the No. field on the LCTable? I would have guessed to use the:
No. - OnValidate()
part?
2) I tried to add this code to copy the description to the LCTable
Description - OnValidate()
IF ("Search Description" = UPPERCASE(xRec.Description)) OR ("Search Description" = '') THEN
"Search Description" := Description;
LCHeader.SETRANGE("No.", "No.");
IF LCHeader.FIND('-') THEN
LCHeader.Description := Description;
But the Description does not copy over? I checked that the LCTable record was there but no joy.
Many thanks for your help.
Mike
RIS Plus, LLC
RIS Plus, LLC
I know that this is bread and butter for the majority of you but please be patient with me while I try to work and understand NAV more in the coding sense.
Thanks,
Mike
IF LCHeader.FIND('-')
THEN BEGIN
LCHeader."Item No." := "No.";
LCHEADER."No." := "No.";
LCHeader.INSERT;
End;
If you wish for the LCheade table to change along with an item no change then you would add code to the OnRename trigger of the item table.
(if your talking about that?) when you said change.
As far as the description thing goes if you don't add a yourtable.MODIFY;
code to you code then nothing will change.
the c/side reference guid can help you with MODIFY.
Since your table seems to be based off the item table then you can see how many things happen from the item table by looking at it's triggers and seeing the code already there. Perhaps you can think about the ondelete trigger too incase the item is deleted.
I suggest doing all these test on a seperate database & testing before ever making it a live function.
http://www.BiloBeauty.com
http://www.autismspeaks.org
http://www.BiloBeauty.com
http://www.autismspeaks.org
RIS Plus, LLC
Well, I have been able to create a LCHeader record OnInsert, but am stuck on the OnRename. I have read the help but still no joy. Basically, the scenario is this.
Item A0001 is created and a record is auto created in the LCHeader table called A0001. A user changed the item No. to A0001A and the LCHeader table's record renames to A0001A as well.
My issues is this, if the user has changed the Item No.(A0001A), where is the previous item No (A0001) stored? I was looking at xRec but that didn't really help me in the coding front.
Thanks,
Mike
OnRename()
LCHeader.SETRANGE("No.", xRec."No.");
IF LCHeader.FIND('-') THEN
BEGIN
LCHeader."No.":= "No.";
LCHeader.RENAME("No.");
END;
I have checked the debugger and it seems that I the recird is found using xRec."No." but it doesn't seem to allow me to rename... I have checked and the primary key is "No."
Thanks for you rhelp,
Mike
Wht do you mean previous Item #? It was changed, isn't that what you wanted?
http://www.BiloBeauty.com
http://www.autismspeaks.org
RIS Plus, LLC