Programatically Creates Line No. in Line

jhanvincent14
Member Posts: 214
I tried Creating Line No. programatically using this code:
//Function GetLineNo
recBMGICollectionDetails2.RESET;
recBMGICollectionDetails2.SETRANGE(recBMGICollectionDetails2."Document No.","No.");
IF recBMGICollectionDetails2.FIND('+') THEN BEGIN
"Line No." := ROUND(recBMGICollectionDetails2."Line No.",1000,'=') + 1000;
END ELSE BEGIN
"Line No." := 1000;
END;
That code is inside in a LOOP condition :
FOR I := 1 TO vTerms DO BEGIN
vCount := vCount + 1;
WITH recBMGICollectionDetails DO BEGIN
INIT;
vBMGIDate := Date;
"Line No." := GetLineNo;
IF vBMGIDate = 0D THEN BEGIN
Date := CALCDATE(vMonths,vDate);
END ELSE BEGIN
Date := CALCDATE(vMonths,vBMGIDate);
END;
"Document Code" := GetNextCode(vStartingNo,vCount);
Amount := ("Lawn Lot Amount"/vTerms);
INSERT;
END;
END;
CurrPage.UPDATE;
But error gave the error Line No. Already Exist. As you see, I already put INSERT so on the next loop the GETLINENO will give me the next the new Value of LINE No. can somebody help me with this? thanks in advance.
//Function GetLineNo
recBMGICollectionDetails2.RESET;
recBMGICollectionDetails2.SETRANGE(recBMGICollectionDetails2."Document No.","No.");
IF recBMGICollectionDetails2.FIND('+') THEN BEGIN
"Line No." := ROUND(recBMGICollectionDetails2."Line No.",1000,'=') + 1000;
END ELSE BEGIN
"Line No." := 1000;
END;
That code is inside in a LOOP condition :
FOR I := 1 TO vTerms DO BEGIN
vCount := vCount + 1;
WITH recBMGICollectionDetails DO BEGIN
INIT;
vBMGIDate := Date;
"Line No." := GetLineNo;
IF vBMGIDate = 0D THEN BEGIN
Date := CALCDATE(vMonths,vDate);
END ELSE BEGIN
Date := CALCDATE(vMonths,vBMGIDate);
END;
"Document Code" := GetNextCode(vStartingNo,vCount);
Amount := ("Lawn Lot Amount"/vTerms);
INSERT;
END;
END;
CurrPage.UPDATE;
But error gave the error Line No. Already Exist. As you see, I already put INSERT so on the next loop the GETLINENO will give me the next the new Value of LINE No. can somebody help me with this? thanks in advance.
0
Answers
-
Try :
IF recBMGICollectionDetails2.FINDLAST THEN BEGIN
"Line No." := recBMGICollectionDetails2."Line No." + 1000;
END ELSE BEGIN
"Line No." := 1000;
END
You can use Autosplitkey property to generate key automatically.
0 -
Sowkarthika wrote: »Try :
IF recBMGICollectionDetails2.FINDLAST THEN BEGIN
"Line No." := recBMGICollectionDetails2."Line No." + 1000;
END ELSE BEGIN
"Line No." := 1000;
END
You can use Autosplitkey property to generate key automatically.
yes. I already did that and the error is still the same. I already set the autosplitkey as yes. I progmatically create this because i want to replicate CREATE CHECK INSTALLMENTS in Post dated checks-Purchase.0 -
First i think you forgot to assign the "Document No."- field when you create a new recBMGICollectionDetails- Line.
Second is to get the last "Line No." from the table to an integer before you enter the creation loop and then use the integer in the creation loop. This would reduce database- access and would work if you do not create additional lines in the table while inserting the actual record.
And third: Autosplitkey is only used on Pages while Inserting in a List.
0 -
First i think you forgot to assign the "Document No."- field when you create a new recBMGICollectionDetails- Line.
Second is to get the last "Line No." from the table to an integer before you enter the creation loop and then use the integer in the creation loop. This would reduce database- access and would work if you do not create additional lines in the table while inserting the actual record.
And third: Autosplitkey is only used on Pages while Inserting in a List.
i want to create multiple line in recBMGICollectionDetails in one click of the button. that's why i put insinde the GETLINENO function inside the loop.0 -
for a quick test, assign for loop I variable to Line No.
"Line No." := I;0 -
mohana_cse06 wrote: »for a quick test, assign for loop I variable to Line No.
"Line No." := I;
I assign it as you said sir. and it works properly. any suggestion ?0 -
I doubt your GetLineNo is not returning correct values.
try passing record variable as parameter and try debugging0 -
@jhanvincent14
What i'm trying to say was, that if your (not called) recBMGICollectionDetails- Insert-Trigger would insert more Lines in recBMGICollectionDetails then you can't use the integer variable.
Did you try to assign the "Document no."?0 -
mohana_cse06 wrote: »I doubt your GetLineNo is not returning correct values.
try passing record variable as parameter and try debugging
I have a question. what is the difference between this two?
FIND('+') AND FIND('+')0 -
jhanvincent14 wrote: »
I have a question. what is the difference between this two?
FIND('+') AND FIND('+')
Both are same0 -
assign it as you said sir. and it works properly. any suggestion0
-
Try This:
/Function GetLineNo : integer // should return an integer BEGIN recBMGICollectionDetails2.RESET; // this rec should be local to the function recBMGICollectionDetails2.SETRANGE(recBMGICollectionDetails2."Document No.","No."); // is "No." as filter variable correct or should it be "Document No."? recBMGICollectionDetails2.FINDlast THEN; // finds last rec if exist exit(recBMGICollectionDetails2."Line No."+1000); // returns "Line No."+1000 or 1000 if no rec exists END;
That code is inside in a LOOP condition :FOR I := 1 TO vTerms DO WITH recBMGICollectionDetails DO BEGIN vCount += 1; INIT; "Document No." := rec."No." // or rec."Document No." if it is better "Line No." := GetLineNo; vBMGIDate := Date; IF vBMGIDate = 0D THEN Date := CALCDATE(vMonths,vDate) ELSE Date := CALCDATE(vMonths,vBMGIDate); "Document Code" := GetNextCode(vStartingNo,vCount); Amount := ("Lawn Lot Amount"/vTerms); INSERT; END; CurrPage.UPDATE;
0 -
mohana_cse06 wrote: »jhanvincent14 wrote: »
I have a question. what is the difference between this two?
FIND('+') AND FIND('+')
Both are same
ow. sorry sir. what i mean si FIND('-') and FIND('+')0 -
-
Try This:
/Function GetLineNo : integer // should return an integer BEGIN recBMGICollectionDetails2.RESET; // this rec should be local to the function recBMGICollectionDetails2.SETRANGE(recBMGICollectionDetails2."Document No.","No."); // is "No." as filter variable correct or should it be "Document No."? recBMGICollectionDetails2.FINDlast THEN; // finds last rec if exist exit(recBMGICollectionDetails2."Line No."+1000); // returns "Line No."+1000 or 1000 if no rec exists END;
That code is inside in a LOOP condition :FOR I := 1 TO vTerms DO WITH recBMGICollectionDetails DO BEGIN vCount += 1; INIT; "Document No." := rec."No." // or rec."Document No." if it is better "Line No." := GetLineNo; vBMGIDate := Date; IF vBMGIDate = 0D THEN Date := CALCDATE(vMonths,vDate) ELSE Date := CALCDATE(vMonths,vBMGIDate); "Document Code" := GetNextCode(vStartingNo,vCount); Amount := ("Lawn Lot Amount"/vTerms); INSERT; END; CurrPage.UPDATE;
Okay sir. I'll try this0 -
jhanvincent14 wrote: »mohana_cse06 wrote: »jhanvincent14 wrote: »
I have a question. what is the difference between this two?
FIND('+') AND FIND('+')
Both are same
ow. sorry sir. what i mean si FIND('-') and FIND('+')
Find('+') Finds Last value of Record and FIND('-') Finds First value Of the Record...:=)
IF ItemRec.FIND('+') THEN
MESSAGE(TEXT004, ItemRec."No.", ItemRec.Description, ItemRec."Unit Price")
ELSE
MESSAGE(TEXT001);0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions