Programatically Creates Line No. in Line

jhanvincent14jhanvincent14 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.

Answers

  • SowkarthikaSowkarthika Member Posts: 102
    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.
  • jhanvincent14jhanvincent14 Member Posts: 214
    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.
  • FiddiFiddi Member Posts: 46
    edited 2017-01-05
    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.
  • jhanvincent14jhanvincent14 Member Posts: 214
    Fiddi wrote: »
    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.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    for a quick test, assign for loop I variable to Line No.
    "Line No." := I;
  • jhanvincent14jhanvincent14 Member Posts: 214
    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 ? :)
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    I doubt your GetLineNo is not returning correct values.
    try passing record variable as parameter and try debugging
  • FiddiFiddi Member Posts: 46
    @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."?
  • jhanvincent14jhanvincent14 Member Posts: 214
    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('+')
  • mohana_cse06mohana_cse06 Member Posts: 5,504

    I have a question. what is the difference between this two?
    FIND('+') AND FIND('+')

    Both are same :D
  • FiddiFiddi Member Posts: 46
    assign it as you said sir. and it works properly. any suggestion
    I think this works only for the first time. if you try this a second time you should get the same error!?
  • FiddiFiddi Member Posts: 46
    edited 2017-01-05
    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;
    
  • jhanvincent14jhanvincent14 Member Posts: 214

    I have a question. what is the difference between this two?
    FIND('+') AND FIND('+')

    Both are same :D

    ow. sorry sir. what i mean si FIND('-') and FIND('+')
  • jhanvincent14jhanvincent14 Member Posts: 214
    Fiddi wrote: »
    assign it as you said sir. and it works properly. any suggestion
    I think this works only for the first time. if you try this a second time you should get the same error!?

    Yes. this error shows on the second loop
  • jhanvincent14jhanvincent14 Member Posts: 214
    Fiddi wrote: »
    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 this
  • SuDSuD Member Posts: 102

    I have a question. what is the difference between this two?
    FIND('+') AND FIND('+')

    Both are same :D

    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);
Sign In or Register to comment.