How to move the selected record pointer in a subform

GaryDGaryD Member Posts: 66
Hello! We've put a button on the Sales Invoice form (43) which when clicked adds a specific item to the subform (47). This seems to work correctly but I can't figure out how to make the new line the selected line after it's created. Specifically I want to call the InsertExtendedText function on the form right after creating the new record but in code after I do the INSERT, Rec doesn't have any values (xRec has what I want), so InsertExtendedText doesn't do anything. What I've got is a new menu button which when clicked calls a routine we've created. Within that routine is this code:

SalesLine.INIT;
SalesLine."Document Type" := SalesHeader."Document Type";
SalesLine."Document No." := SalesHeader."No.";
SalesLine."Line No." := LineNo;
SalesLine.VALIDATE("Sell-to Customer No.", SalesHeader."Sell-to Customer No.");
SalesLine.VALIDATE(Type, SalesLine.Type::Item);
SalesLine.VALIDATE("No.", 'E87360001');
SalesLine.VALIDATE(Quantity, 1);
SalesLine.INSERT;
currform.update;
message("No."); //
returns nothing

as a side request, if anybody knows how to set the top row (scroll a list to make a certain line the first visible line in the window) that would be appreciated too!

Thanks!

Comments

  • SavatageSavatage Member Posts: 7,142
    edited 2008-11-25
    OnPush()
    IF Status = Status::Open
    THEN BEGIN
      SalesLine.RESET;
      SalesLine.SETRANGE(SalesLine."Document Type","Document Type");
      SalesLine.SETRANGE(SalesLine."Document No.","No.");
       IF SalesLine.FIND('+')
        THEN BEGIN
         SalesLine."Line No." := SalesLine."Line No." + 10000;
         SalesLine.Type := SalesLine.Type::Item;
         SalesLine.VALIDATE(SalesLine."No.", 'E87360001');
         SalesLine.VALIDATE(SalesLine.Quantity, 1);
         SalesLine.INSERT;
         CurrForm.SalesLines.FORM.InsertExtendedText(TRUE); 
        END ELSE BEGIN
         SalesLine."Line No." :=  SalesLine."Line No." + 10000;
         SalesLine.Type := SalesLine.Type::Item;
         SalesLine.VALIDATE(SalesLine."No.", 'E87360001');
         SalesLine.VALIDATE(SalesLine.Quantity, 1);
         SalesLine.INSERT;
         CurrForm.SalesLines.FORM.InsertExtendedText(TRUE);   
        END;
    END
    ELSE BEGIN
      MESSAGE('Sales order %1 must be Open!',"No.");
    END;
    
  • SavatageSavatage Member Posts: 7,142
    edited 2008-11-25
    as a side request, if anybody knows how to set the top row (scroll a list to make a certain line the first visible line in the window) that would be appreciated too!

    So you want the cursor on the top line...When? when to form opens?
    Change the SourceTablePlacement = First

    Also many people made custom changes to the InsertExtText - So I assumed you didn't.

    Also you can set that Item Number as a variable in a setup form like the Inventory Setup.
    That way it can be changed easily at some pint if needed.

    Ex/ Add A field to the Invtory Setup - "MY Default No." or whatever.

    Then the code would look like...
    OnPush()
    IF Status = Status::Open
    THEN BEGIN
      InvtSetup.Get;
      SalesLine.RESET;
      SalesLine.SETRANGE(SalesLine."Document Type","Document Type");
      SalesLine.SETRANGE(SalesLine."Document No.","No.");
       IF SalesLine.FIND('+')
        THEN BEGIN
         SalesLine."Line No." := SalesLine."Line No." + 10000;
         SalesLine.Type := SalesLine.Type::Item;
         SalesLine.VALIDATE(SalesLine."No.", "My Default No."');
         SalesLine.VALIDATE(SalesLine.Quantity, 1);
         SalesLine.INSERT;
         CurrForm.SalesLines.FORM.InsertExtendedText(TRUE);
        END ELSE BEGIN
         SalesLine."Line No." :=  SalesLine."Line No." + 10000;
         SalesLine.Type := SalesLine.Type::Item;
         SalesLine.VALIDATE(SalesLine."No.", "My Default No."');
         SalesLine.VALIDATE(SalesLine.Quantity, 1);
         SalesLine.INSERT;
         CurrForm.SalesLines.FORM.InsertExtendedText(TRUE);
        END;
    END
    ELSE BEGIN
      MESSAGE('Sales order %1 must be Open!',"No.");
    END;
    
  • GaryDGaryD Member Posts: 66
    Thanks for the reply Savatage. The InsertExtendedText process still is not working correctly. If I start with one line showing in the subform, this line is the selected line. If I then click my menu button to run the CAL code that inserts the new line, the record selector on the subform is STILL on the first line, so the InsertExtendedText runs against this first record and not the record I just inserted. So my problem still seems to be that I can't make my newly inserted line the selected line on the subform before calling InsertExtendedText.
  • kinekine Member Posts: 12,562
    You need to change record which is in the Rec variable of the form. By doing FIND or Next or Get (depends on what you know about the new line).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    GaryD wrote:
    ... If I start with one line showing in the subform, this line is the selected line.
    ... the record selector on the subform is STILL on the first line,
    ...So my problem still seems to be that I can't make my newly inserted line the selected line on the subform ...

    This is an issue with SubForms since day one of Financials. now with the release of 2009, I seriously doubt that this issue will ever be addressed.

    You will need to rethink the logic. Basically and code to manipulate data and cursors in a SubForm is very complex to make work. The effort to make it work will be more than the value of the functionality.
    David Singleton
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    GaryD wrote:
    ... If I start with one line showing in the subform, this line is the selected line.
    ... the record selector on the subform is STILL on the first line,
    ...So my problem still seems to be that I can't make my newly inserted line the selected line on the subform ...

    http://www.mibuso.com/forum/viewtopic.php?f=23&t=26946
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • GaryDGaryD Member Posts: 66
    Thanks to all for the replies. I've made some notes to refer to if it happens again. But lst night I ended up doing what my boss had suggested in the first place - I made a made a new function called InsertExtendedText2, just like the InsertExtendedText but this one gets a Record parameter passed in to it. I call that one instead of the original and things seem to be working ok now. Thanks again!
  • SavatageSavatage Member Posts: 7,142
    OnPush()
    IF Status = Status::Open
    THEN BEGIN
    SalesLine.RESET;
    SalesLine.SETRANGE(SalesLine."Document Type","Document Type");
    SalesLine.SETRANGE(SalesLine."Document No.","No.");
    IF SalesLine.FIND('+') <<If lines exist it add the new line to the end!
    THEN BEGIN
    SalesLine."Line No." := SalesLine."Line No." + 10000;
    SalesLine.Type := SalesLine.Type::Item;
    SalesLine.VALIDATE(SalesLine."No.", 'E87360001');
    SalesLine.VALIDATE(SalesLine.Quantity, 1);
    SalesLine.INSERT;
    CurrForm.SalesLines.FORM.InsertExtendedText(TRUE);
    END ELSE BEGIN <<Else it makes it the first line
    SalesLine."Line No." := SalesLine."Line No." + 10000;
    SalesLine.Type := SalesLine.Type::Item;
    SalesLine.VALIDATE(SalesLine."No.", 'E87360001');
    SalesLine.VALIDATE(SalesLine.Quantity, 1);
    SalesLine.INSERT;
    CurrForm.SalesLines.FORM.InsertExtendedText(TRUE);
    END;
    END
    ELSE BEGIN
    MESSAGE('Sales order %1 must be Open!',"No.");
    END;

    I got this to work by copying the exact ONPUSH code from the Insert Extended Text function.
    Mine was CurrForm.SalesLines.FORM.InsertExtendedText(TRUE);

    One other way would be to copy the InsertExtendedText Function from the the Sales Header to the Sales line form too.

    We've modified our insert Extended Text to only happen on "release" of the order by adding
    CurrForm.SalesLines.FORM.InsertExtendedText(TRUE); to the menu item release OnPush

    KIne's Post above says you need to probably do another find so perhaps after the insert do the find again????

    SalesLine.RESET;
    SalesLine.SETRANGE(SalesLine."Document Type","Document Type");
    SalesLine.SETRANGE(SalesLine."Document No.","No.");
    IF SalesLine.FIND('+') THEN BEGIN
    CurrForm.SalesLines.FORM.InsertExtendedText(TRUE);

    My thought is if they are two different functions both usually run seperately from different menu items ONPUSH
    You should be able to take the code from the InsertExtendedText function ONPUSH and add it to this new function ONPUSH and it should still run.
  • SavatageSavatage Member Posts: 7,142
    ps I made a mistake on the above codes I used item #255 which is an item of mine - used to test. _ i edited the above posts to fix the item # used.
Sign In or Register to comment.