Set focus on subform/field in subform.

imurphyimurphy Member Posts: 308
The little bit of code below is attached to a button on a sales order form. It creates a new record and inserts a series number and a client ref. This much works fine.

I wanted to set user to be able to press button and to have the focus jump directly to the subform so they can start using a barcode reader.

The setting focus bit is not working though. When I execute the line 'CurrForm.SalesLines.ACTIVATE' it asks me if I want to rename the record.

Any suggestions as to what I'm doing wrong?
recSalesHeader.INSERT(TRUE);
SalesSetup.GET;
NextOrderNo := NoSeriesMgt.GetNextNo (SalesSetup."Order Nos.", WORKDATE, TRUE);

recSalesHeader."Document Type" := recSalesHeader."Document Type"::Order;
recSalesHeader."No." := NextOrderNo ;
recSalesHeader.VALIDATE ("No.");
recSalesHeader."Sell-to Customer No." := 'CL000001';
recSalesHeader.VALIDATE ("Sell-to Customer No.", 'CL000001');
recSalesHeader.INSERT;

Rec.GET (recSalesHeader."Document Type", recSalesHeader."No.");

//CurrForm.ACTIVATE;
//CurrForm.SalesLines.ACTIVATE;

Comments

  • XypherXypher Member Posts: 297
    edited 2008-07-24
    What is with the two 'recSalesHeader.INSERT's ? Where's the INIT call?
  • imurphyimurphy Member Posts: 308
    Copying and pasting code...

    I missed the init.

    The second insert should be a modify. Its a work in progress... :?
  • XypherXypher Member Posts: 297
    When you fix those lines of code does it solve the issue you were experiencing?
  • SavatageSavatage Member Posts: 7,142
    i added
    CurrForm.SalesLines.ACTIVATE;
    to the last code of the Onpush trigger of a command button on the sales header and it goes right to the first sales line.
  • imurphyimurphy Member Posts: 308
    the above code is, well, wrong. Sorry about that.

    So, I've just gone back over it and this makes a little more sense:
    recSalesHeader.INIT;
    recSalesHeader."Document Type" := recSalesHeader."Document Type"::Order;
    recSalesHeader.INSERT(TRUE);
    
    recSalesHeader."Sell-to Customer No." := 'CL000001';
    recSalesHeader.VALIDATE ("Sell-to Customer No.");
    
    recSalesHeader.MODIFY;
    Rec.GET (recSalesHeader."Document Type", recSalesHeader."No.");
    CurrForm.SalesLines.ACTIVATE;
    

    and THIS code asks me if I want to rename the record. I have it attached to a button on the sales order form.
    It should just create a standard order for client 1 and jump the user to the first sales line.... no?

    Ian
  • imurphyimurphy Member Posts: 308
    I should add that if you comment out the last line it works perfectly - apart from the focus thing.
    If you add the line back it asks if its ok to rename.
  • XypherXypher Member Posts: 297
    edited 2008-07-24
    I'm a bit unsure as to why you're inserting a portion of the record and in the proceeding lines of code modifying the rest. Why not assign all the field values after the initialization and prior to the insertion?

    If your Sales Header table (36) is the same as mine, you will notice the primary key is "Document Type,No." aka you are only assigning HALF of the primary key in your first "partial" insertion. THEN assigning the other half of the primary key which would be resulting in the question "Rename record?".

    When you do not have the Activation line of code, it is assumed the record is still in focus and thus it wont ask you if you want to rename the record.

    --- edit ---

    It also appears there is no reason for you to call the VALIDATE function. You should be executing the code in the following order: INIT, Assign Field Values, INSERT. (The OnValidate function gets called, post-INSERT, since you are assigning the field's value for the first time. Correct me if I am wrong, but if you were to modify any of an existing record's fields, related to the implied field's OnValidate function, it is then and only then that you will want to call the VALIDATE function.)
  • imurphyimurphy Member Posts: 308
    The Insert(True) does the lookup/insertion of the document number - so the second part of the key is automatically added as I have this ticked on the number series.

    It also auto completes various other fields like document date. The default is ok by me so I make use of this.

    I've checked with the debugger and by checking the sales header table - The header I am writing is correctly completed with type, next number in series, doc date, etc etc

    You've got a point on the insert and then modify, its not necessary.

    The record which is displayed after pressing the button is the new record, so I'm not sure what you mean by
    When you do not have the Activation line of code, it is assumed the record is still in focus and thus it wont ask you if you want to rename the record.

    I have the impression that its an event queue problem or something similar. I think I need to do something like 'do-all-pending-operations();' and then set the focus to the subform.
  • XypherXypher Member Posts: 297
    edited 2008-07-24
    Ok, how about... within your OnInsert code, do you issue a RENAME or MODIFY after you have obtained and wish to apply the new document "No."?
  • DenSterDenSter Member Posts: 8,305
    Xypher wrote:
    I'm a bit unsure as to why you're inserting a portion of the record and in the proceeding lines of code modifying the rest.
    That is actually a very good way of doing it. INIT the sales header, set the doc type, make sure the number is blank and do INSERT(TRUE), which will retrieve the next number out of the numbering series. Then you populate the rest of the fields and do a MODIFY(TRUE). Nothing wrong with that.
  • DenSterDenSter Member Posts: 8,305
    imurphy wrote:
    Rec.GET (recSalesHeader."Document Type", recSalesHeader."No.");
    
    and THIS code asks me if I want to rename the record.
    That's because you do a GET of your new sales header into Rec, which is a different record. You're on a form, so it tries to write that into the database; the primary key values have changed, so the system thinks you want to RENAME, the DBMS kicks in and you get the message. Maybe you can tell us what you want to accomplish, and we can help you.
  • SavatageSavatage Member Posts: 7,142
    I Tried this modified from your code
    OnPush()
    RECSALESHEADER.INIT; 
    RECSALESHEADER."Document Type" := RECSALESHEADER."Document Type"::Order; 
    RECSALESHEADER.VALIDATE("Sell-to Customer No.",'CL000001');
    RECSALESHEADER.INSERT(TRUE); 
    
    CurrForm.SalesLines.ACTIVATE; 
    CLEAR(RECSALESHEADER."Document Type");
    CLEAR(RECSALESHEADER."No.");
    
    I do get a salesheader & it goes to the salesline.

    probably change this to
    Rec.GET ("Document Type","No.");
    
    since at that point of the code it exists ??? what is this code supposed to do? why do you need it?
  • imurphyimurphy Member Posts: 308
    The idea is pretty simple. The user clicks on the button to do the following operations: create a new record, fill out the new document reference, fill out a particular client and several other fields with default values. It then selects the first row of the sales lines and exits. If I have Order001 on the screen then the button will leave the user looking at Order002.

    If I have an order open the Rec variable points to an existing record. If I create a new SalesHeader and populate the fields I then have to get the form to 'load' this new record.

    What I need to get/load/read into the form is an order (recSalesHeader."Document Type") with a reference of recSalesHeader."No."

    Hence Rec.Get (recSalesHeader."Document Type", recSalesHeader."No.");

    Denster, you said:
    That's because you do a GET of your new sales header into Rec, which is a different record. You're on a form, so it tries to write that into the database; the primary key values have changed, so the system thinks you want to RENAME, the DBMS kicks in and you get the message.

    maybe I've misunderstood the function of get, but my understanding is that rec.get(x,y) gets/loads/reads the record with key x,y into the variable rec. Since the form is based on Rec it will display the newly loaded rec. Theres nothing mentioned in the docs about any implicit rename or write operation of updated values when you perform an operation on a record. If you don't explicitly write something out, any modified values are dropped, no?

    Savatage, the code you posted is shorter but similar to what I had. I can't see how are you getting nav to display Order002 instead of Order001 and why are you then clearing the keys?
    CLEAR(RECSALESHEADER."Document Type");
    CLEAR(RECSALESHEADER."No.");

    You said to change the rec.get code
    probably change this to Code:
    Rec.GET ("Document Type","No.");

    since at that point of the code it exists ??? what is this code supposed to do? why do you need it?

    However since nav has an Implicit 'With Rec begin....' around all code in a form Rec.Get ("Document Type", "No.") is just a short way of saying
    Rec.Get (Rec."Document Type", Rec."No.") 
    

    Which should have no effect at all since it will reload the current record... no?
  • SavatageSavatage Member Posts: 7,142
    edited 2008-07-24
    I cleared them because when I tried that code without clearing them - the next time you click the button it gives a message that the document already exists and the only way to create another order was to close the form and re-open it.

    by clearing it It made the code keep adding new orders with each click.
  • DenSterDenSter Member Posts: 8,305
    imurphy wrote:
    The idea is pretty simple. The user clicks on the button to do the following operations: create a new record, fill out the new document reference, fill out a particular client and several other fields with default values. It then selects the first row of the sales lines and exits. If I have Order001 on the screen then the button will leave the user looking at Order002.
    I think I would put that button on the customer card, like 'create an order for this customer'.
    imurphy wrote:
    my understanding is that rec.get(x,y) gets/loads/reads the record with key x,y into the variable rec. Since the form is based on Rec it will display the newly loaded rec. Theres nothing mentioned in the docs about any implicit rename or write operation of updated values when you perform an operation on a record. If you don't explicitly write something out, any modified values are dropped, no?
    That would have been my initial understanding as well, but obviously it is not working that way is it :mrgreen:. You are getting the 'do you want to rename' message, so it must think you are trying to rename the record. I am trying to make sense of that message, so I'm just thinking of why the system would think that. Coming from the original Rec (with number Order001), you create a new sales header (Order002) and 'load' it into Rec. The form now thinks "wait a minute, Rec was Order001, and now it is Order002, let's make sure the database is up to date". This is something you will need to debug to make sure what it is doing exactly, and probably go with a different approach.

    Maybe you need to do a Currform.UPDATE(TRUE) before creating the new sales header. Maybe you will need to do Rec.INIT and build the new order straight into Rec. Debug the process and see what is going on.
  • SavatageSavatage Member Posts: 7,142
    That posted code was tested on my sales order header card where I put a command button with that code. I assumed your form is working like the sales header & sales lines. And the No series is working.


    It worked for me - whats isn't it doing for you?
  • imurphyimurphy Member Posts: 308
    Savatage,
    My form is a copy of the standard order form with a few fields and buttons removed to simplify it down... so far only a few but I will be removing all but the essentials.

    I copied your lines onto a button and the rename dialog appears. I have 'default Nos.' marked and 'Manual nos.' unmarked on the series. It appears if I execute any currform.xxxx function. If I remove the line it creates a new record but does not display it... since there is nothing which is telling nav to display the newly created record I'm not sure how this is working on your system.

    Denster,
    This is for 'sort of' retail use - only a few sales a day. Due to high staff turnover and the low usage they will make of this single nav terminal and a desire to not to have to train them on filling out all the bits of a sales form I wanted one which needed as little knowledge of nav as possible.

    I have already tried doing this with the debugger enabled for break on triggers.... no use. I get to the line in question press F8 and the dialog appears. I click on ok or cancel and it continues on without having displayed any code doing a rename.

    :-k I think I'm going to drop this one for now as its not exactly critical and they can just use the mouse. I'll come back to it one day.

    Thanks for the help on this one guys.

    Ian
  • SavatageSavatage Member Posts: 7,142
    I thought you wanted to create a header and have it pop down to the salesline and that was it.

    I'm getting the sence that you also want info on the sales line filled like Type or something?

    or is the problem that once you click the button - the order is created but the form is not displaying that new order - your still sitting on the first order. And each click of the button does create more and more orders but you want it to move to that order - do I have it correct now?
  • SavatageSavatage Member Posts: 7,142
    recsalesheader - record - sales header
    OnPush()
    recSalesHeader.INIT; 
    recSalesHeader."Document Type" := recSalesHeader."Document Type"::Order; 
    recSalesHeader.VALIDATE("Sell-to Customer No.",'Your Cust#');
    recSalesHeader.INSERT(TRUE); 
    SETFILTER("No.",recSalesHeader."No.");
    CurrForm.SalesLines.ACTIVATE; 
    CLEAR(recSalesHeader."Document Type");
    CLEAR(recSalesHeader."No.");
    

    now the setfilter will will bring you to the new salesorder each time.
    It will also be the only order showing if you hit the list. You would have to clear filters (with ShowAll) to see all the orders.

    I get no rename message.
    if i click the button 100x I get 100 orders for the SET cust #
    and the cursor is always sitting on the first line of the salesline subform.
Sign In or Register to comment.