HI everyone.. I'm having a lot of trouble trying to insert records of a vendor in a table.. In this case I already have a record and I need to update (modify) the content but It raises a error that this record already exists.
I was trying to find the existing record making
prodform."Vendor No.":="Source No.";
IF prodform.FIND('=') THEN BEGIN
I also tried just to do
IF prodform.FINDFIRST() THEN BEGIN
But nothing is working.. here's the code and images of the problem... where prodform is a record of "Produtos Fornecedor" table which have the fields Vendor No (supplied by the table Vendor), Data Ultima Compra, Preço, Quantidade, Item No. (linked to Item table) and Vendor Name (flowfield with Lookup(Vendor.Name WHERE (No.=FIELD(Vendor No.))) )
IF "Item Ledger Entry Type"=0 THEN BEGIN
prodform.SETRANGE("Item No.",Item."No.");
prodform.SETRANGE("Vendor No.","Source No.");
Item."Data Ultima Compra":="Posting Date";
Item."Vendor No.":="Source No.";
prodform."Vendor No.":="Source No.";
IF prodform.FIND('=') THEN BEGIN
prodform."Data Ult. Compra":="Posting Date";
prodform.Quantidade:="Invoiced Quantity";
prodform.Preço:=ValueEntry."Cost per Unit";
prodform.MODIFY;
END
ELSE BEGIN
prodform.INIT;
prodform."Vendor No.":="Source No.";
prodform."Data Ult. Compra":= "Posting Date";
prodform.Quantidade:="Invoiced Quantity";
prodform.Preço:=ValueEntry."Cost per Unit";
prodform."Item No.":=Item."No.";
prodform.INSERT;
END;
Item.MODIFY;
END;
Answers
prodform.SETRANGE("Item No.",Item."No.");
prodform.SETRANGE("Vendor No.","Source No
IF prodform.FINDFIRST THEN BEGIN
// Write here
END;
This line of code won't be needed
IF prodform.FIND('=') THEN BEGIN// Remove this
What is the primary key of this table - prodform
While INIT INSERT make sure primary key part ha no issue.
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/
IF "Item Ledger Entry Type"=0 THEN BEGIN
prodform.RESET;
prodform.SETRANGE("Item No.",Item."No.");
prodform.SETRANGE("Vendor No.","Source No.");
Item."Data Ultima Compra":="Posting Date";
Item."Vendor No.":="Source No.";
IF prodform.FINDFIRST THEN BEGIN
prodform."Data Ult. Compra":="Posting Date";
prodform.Quantidade:="Invoiced Quantity";
prodform.Preço:=ValueEntry."Cost per Unit";
prodform.MODIFY;
END
ELSE BEGIN
prodform.INIT;
prodform."Vendor No.":="Source No.";
prodform."Data Ult. Compra":= "Posting Date";
prodform.Quantidade:="Invoiced Quantity";
prodform.Preço:=ValueEntry."Cost per Unit";
prodform."Item No.":=Item."No.";
prodform.INSERT;
END;
Item.MODIFY;
Remove these lines
prodform.RESET;
prodform.SETRANGE("Item No.",Item."No.");
prodform.SETRANGE("Vendor No.","Source No.");
IF prodform.FINDFIRST THEN BEGIN
Instead of these 4 lines write
prodform.GET(Item."No.","Source No.");
What is the error that you are receiving at FINDFIRST?
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/
@Kepty is right. You can clearly see that your primary key is Vendor No from the error message.
Design your prodform table, go to View->Keys and edit your primary key fields (check for example Table 99).
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Wasn't this clear in my statement
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/
Please verify the answer.
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/