Using INSERT FUNCTION

Please I am trying to use the INSERT command attached to a record reference in a posting

routine but it is not achieving the desired result. It’s is supposed to populate a particular

table “Account” but it does not. However I find the information in the pages that are connected

to this table “Account”. The pages are Account Details Card and Account List.

Can any one kindly explain to me why this is happening and also help on resolving this issue.

I am using dynamics nav 2013.

Below is the line of Code that I am using :

IF CONFIRM(Text001) THEN BEGIN

TESTFIELD(“Customer Code”);

TESTFIELD(“Branch Code”);

TESTFIELD(“Acc Cat Code”);

TESTFIELD(“Voucher No.”);

AccountCat.GET(“Acc Cat Code”);

AccountLines.RESET;

AccountLines.SETRANGE(AccountLines.“Parent Code”, “Customer Code”, “Customer Code”);

{Clients.SETRANGE(“Customer Code”);}

Clients.SETRANGE(“No.”);

//Loop through the Lines and create an account for each client//

IF AccountLines.FIND(’-’) THEN BEGIN

REPEAT

IF AccountLines.“Create Account” = TRUE THEN BEGIN

//Generate Number from No. Series and create account number

AccountCat.GET(“Acc Cat Code”);

IF AccountCat.“Account Cat No. Series” = ‘’ THEN

ERROR(Text003, “Acc Cat Code”);

AccountNo := NoSeriesMgt.GetNextNo(AccountCat.“Account Cat No. Series”, 0D, TRUE);

AccountNo := “Branch Code”+AccountNo;

Clients.RESET;

{ Clients.SETFILTER(“Customer Code”, AccountLines.“Customer Code”); }

Clients.SETFILTER(“No.”, AccountLines.“Customer Code”);

IF Clients.FIND(’-’) THEN BEGIN

Accounts.INIT;

Accounts.“Account No.” := AccountNo;

AcType := AccountCat.“Account Cat Type”;

IF AccountCat.“Account Cat Type” = AccountCat.“Account Cat Type”::“Term Deposit” THEN

Accounts.“Term Deposit” := TRUE;

Accounts.“Branch Code” := “Branch Code”;

Accounts.“Acc Cat Code” := “Acc Cat Code”;

Accounts.“Customer Code” := AccountLines.“Customer Code”;

Accounts.“Account Name” := AccountLines.“Account Name”;

Accounts.“Customer Type” := Clients.“Customer Type”;

Accounts.“Search Name” := Accounts.“Account Name”;

Accounts.“Currency Code” := AccountCat.Currency;

Accounts.“Agent Code” := Clients.“Agent Code”;

Accounts.“Print Statement” := AccountCat.“Print Statement”;

Accounts.“Last Print Date” := AccountCat.“Last Print Date”;

Accounts.“Voucher No.” := “Voucher No.”;

Accounts.“Date Opened” := WORKDATE;

Accounts.Status := Accounts.Status::Opened;

Accounts.“Available Balance” := 0;

Accounts.“Actual Balance” := 0;

Accounts.“Uncleared Effects” := 0;

Accounts.“Overdraft Amount” := 0;

//Update process dates--------------------------------------------------

Accounts.“Last Debit Interest” := WORKDATE;

Accounts.“Last Credit Interest” := WORKDATE;

Accounts.“Last Credit Application” := WORKDATE;

Accounts.“Last COT” := WORKDATE;

Accounts.“Last TD Activity Date” := WORKDATE;

Accounts.“Last Charge Date” := WORKDATE;

//Copy Mandate from Clients Table

Accounts.Mandate := Clients.Mandate;

Clients.CALCFIELDS(Signature);

Accounts.Signature := Clients.Signature;

Clients.CALCFIELDS(Picture1);

Accounts.Picture1 := Clients.Picture1;

Clients.CALCFIELDS(Picture2);

Accounts.Picture2 := Clients.Picture2;

Clients.CALCFIELDS(Picture3);

Accounts.Picture3 := Clients.Picture3;

Clients.CALCFIELDS(Picture4);

Accounts.Picture4 := Clients.Picture4;

//------------------------------

Accounts.INSERT;

PostedLines.INIT;

PostedLines.“Header Code” := AccountLines.“Header Code”;

PostedLines.“Customer Code” := AccountLines.“Customer Code”;

PostedLines.“Parent Code” := AccountLines.“Parent Code”;

PostedLines.“Account Name” := AccountLines.“Account Name”;

PostedLines.“Create Account” := AccountLines.“Create Account”;

PostedLines.“Copy Mandate” := AccountLines.“Copy Mandate”;

PostedLines.“Account No.” := AccountNo;

PostedLines.INSERT;

AccountNo := ‘’;

END

END;

UNTIL AccountLines.NEXT = 0;

END;

// copy header record to posted account creation header table

PostedHeader.INIT;

PostedHeader.TRANSFERFIELDS(Rec);

PostedHeader.“Post Date” := WORKDATE;

PostedHeader.INSERT;

AccountLines.RESET;

AccountLines.SETFILTER(“Header Code”, “No.”);

IF AccountLines.FIND(’-’) THEN

AccountLines.DELETEALL;

DELETE;

Clients.RESET;

MESSAGE(Text002);

END;

So, just briefly looking at your code, I see a DELETE statement on the 4th-from-the-bottom line. What record is that command operating against? I can’t really tell for sure. And what happens if you rem that line out? I’m just wondering whether you’re inadvertently deleting the record you’re trying to create?