Hi ALL,
I am creating a 100 general journal lines through code, When I call the report it is not working can anyone help me, I am sharing my code pls check and help me.
Hi ALL,
I am creating a 100 general journal lines through code, When I call the report it is not working can anyone help me, I am sharing my code pls check and help me.
This code should work.
I think the other code samples will run into error because the line number is not incremented.
report 50141 "Gen Journal Creation" { UsageCategory = ReportsAndAnalysis; ApplicationArea = All; ProcessingOnly = true; dataset { dataitem(Integer; Integer) { DataItemTableView = sorting(Number); trigger OnPreDataItem() var begin Setrange(Number, 1); end; trigger OnAfterGetRecord() var GenJournalLine: Record "Gen. Journal Line"; i: Integer; LineNo: Integer; begin for i := 1 to 100 do begin GenJournalLine.Init(); GenJournalLine.Validate("Journal Template Name", 'General'); GenJournalLine.Validate("Journal Batch Name", 'Default'); LineNo =10000; GenJournalLine."Line No." := LineNo; GenJournalLine.Insert(true); GenJournalLine."Posting Date" := WorkDate(); GenJournalLine."Document Type" := GenJournalLine."Document Type"::Payment; GenJournalLine."Account Type" := GenJournalLine."Account Type"::Customer; GenJournalLine."Account No." := '20000'; GenJournalLine.Amount := 100.00; GenJournalLine."Bal. Account Type" := GenJournalLine."Bal. Account Type"::"G/L Account"; GenJournalLine."Bal. Account No." := '10100'; GenJournalLine.Modify(); end; Message('100 journals are created.'); end; } } requestpage { layout { area(Content) { group(GroupName) { // field(Name; SourceExpression) // { // ApplicationArea = All; // } } } } actions { area(processing) { action(ActionName) { ApplicationArea = All; } } } } var myInt: Integer; }
Hi,
I think in my given code, this was already done.
Updated code:
report 50141 "Gen Journal Creation"
{
UsageCategory = ReportsAndAnalysis;
ApplicationArea = All;
ProcessingOnly = true;
dataset
{
dataitem(Integer; Integer)
{
DataItemTableView = sorting(Number);
trigger OnPreDataItem()
var
begin
Setrange(Number, 1);
end;
trigger OnAfterGetRecord()
var
GenJournalLine: Record "Gen. Journal Line";
i: Integer;
begin
for i := 1 to 100 do begin
GenJournalLine.Init();
GenJournalLine.Validate("Journal Template Name", 'General');
GenJournalLine.Validate("Journal Batch Name", 'Default');
GenJournalLine."Line No." += 10000;
GenJournalLine.Insert(true);
GenJournalLine."Posting Date" := WorkDate();
GenJournalLine."Document Type" := GenJournalLine."Document Type"::Payment;
GenJournalLine."Account Type" := GenJournalLine."Account Type"::Customer;
GenJournalLine."Account No." := '20000';
GenJournalLine.Amount := 100.00;
GenJournalLine."Bal. Account Type" := GenJournalLine."Bal. Account Type"::"G/L Account";
GenJournalLine."Bal. Account No." := '10100';
GenJournalLine.Modify();
end;
Message('100 journals are created.');
end;
}
}
requestpage
{
layout
{
area(Content)
{
group(GroupName)
{
// field(Name; SourceExpression)
// {
// ApplicationArea = All;
// }
}
}
}
actions
{
area(processing)
{
action(ActionName)
{
ApplicationArea = All;
}
}
}
}
var
myInt: Integer;
}
Regards
Amit Sharma
www.erpconsultors.com
1.Need to increment Line No every time you want to create lines
Second solution
2. Before creating General journal lines get last line No and increment every time in Loop
You are getting the error because the line no is part of the primary key on the journal line. So you need to make sure the line no. is unique for every line.
In the base application the line no. is increased by 10000 for every line that is inserted so there is space to put lines in between two existing lines.
Your problem is in this codeline.
GenJournalLine."Line No." := LineNo;
You need to increment the line no for every line you insert.
Define an integer variable LineNo
Increment the LinoNo for every line you insert
LineNo +=10000;
GenjorunalLine."Line No." := LineNo;
Hi Sams
The error is because you haven't posted the journal lines imported.
You might need to post them before the next 100 lines else you could create a new variable for Gen. Jnl Line and do a findlast and receive the line no.
Hope this helps!
Hi Nitin,
I have tried your code it worked well for first time but when I call the report for second time it is showing the error,
Thanks & Regards.
Sams
Hi,
More fine way to do that.
report 50141 "Gen Journal Creation"
{
UsageCategory = ReportsAndAnalysis;
ApplicationArea = All;
ProcessingOnly = true;
trigger OnPostReport()
var
GenJournalLine: Record "Gen. Journal Line";
i: Integer;
LineNo: Integer;
begin
LineNo := 10000;
for i := 1 to 100 do begin
GenJournalLine.Init();
GenJournalLine.Validate("Journal Template Name", 'General');
GenJournalLine.Validate("Journal Batch Name", 'Default');
GenJournalLine."Line No." := LineNo;
GenJournalLine.Insert(true);
GenJournalLine."Posting Date" := WorkDate();
GenJournalLine."Document Type" := GenJournalLine."Document Type"::Payment;
GenJournalLine."Account Type" := GenJournalLine."Account Type"::Customer;
GenJournalLine."Account No." := '20000';
GenJournalLine.Amount := 100.00;
GenJournalLine."Bal. Account Type" := GenJournalLine."Bal. Account Type"::"G/L Account";
GenJournalLine."Bal. Account No." := '10100';
GenJournalLine.Modify();
LineNo += 10000;
end;
end;
}
|
Hi,
Updated code:
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,564 Super User 2024 Season 2
Martin Dráb 228,651 Most Valuable Professional
nmaenpaa 101,148