[SOLVED] Return to current record after insert

Hi All,
I have created a Master/Detail application. When loading the application, I have set SQL sort order to ‘inserted date - desc’ so it always shows the most recent record.

Problem I am facing now is, after insert of a record it goes to the beginning of the records rather than returning to the last record inserted. So then I have to click on ‘First’ (<<) button to go to the last record to enter remaining data in detail form. Is there anyway to return to the last record after insert?

If I change the sql sort order to ‘inserted date - asc’ then there is no issues after insert as when it return to the beginning it will be the last record. Then every time I load the form I have to click on ‘Last’ (>>) button to view the most recent record.

Anyone has any idea for this?
Thank you.
Aari

Perhaps the following work-around will work. Create an even onafterinsert and do a sc_redir to the same application. It might be necessary to do a sc_committrans before to save the current data into your database.

Great, worked well. Thanks Albert.

Just in case anyone needs it …
We have found that some end users need to return to a list view straight after inserting or deleting a form record
Default behavior is something like this

  • Grid view
  • Insert record
  • Save record
  • New blank record created
Sometimes this new blank record confuses -- although power users like it By changing a setting in the form => Application=>Navigation pane you can get it to go like this
  • Grid view
  • Insert record
  • Save record
  • View saved record
In our current project what we needed was
  • Grid view
  • Insert record
  • Save record
  • Back to grid
and similar for delete

Here’s what worked for us. Haven’t tested it extensively


/**
* Sometimes end users don't like SC offering a new blank session after an insert 
* or a another record to delete following a delete.
* This workaround returns the user to a list view immediately after a new insert or delete 
**/


// OnApplicationInit

// Mark the record if this is a new load
[session_inserted] = False;
[session_deleted] = False;


// onLoad
// Has an insert or a delete just happened?
if ([session_inserted] ==True || [session_deleted] == True){    
    // Reset flags 
    [session_inserted] = False;
    [session_deleted] = False;
    sc_exit();
}

//onAfterInsert
// Flag if a successful insert
[session_inserted] = True;

// onAfterDelete
// Flag if record has been successfully deleted
[session_deleted] = True;

Two new variables are used
[session_inserted]
[session_deleted]
Make sure that both are set in the Global variable space to

  • Input
  • Session

@prema

Thank you so much for your post. It helps me.
I use sc 9.0
After I used your code, My browser jumped out the window and redirect to my SC development panel after I inserted a new record.
I think it is because sc_exit()
sc_exit() doesn’t bring me to the inserted record but bring me to my sc development panel.
Additionally, I have to set these 2 global as
“out”
If I set it as “in”, I will be requested to input the initial value when I open the app.
If you have any idea, please help me.
Thank you~~

by the way, I refer to form application.

use an option in your sc_exit
[TABLE=“cellpadding: 0, cellspacing: 0”]
[TR]
[TD]sc_exit(Option)[/TD]
[/TR]
[TR]
[TD] [TABLE]
[TR]
[TD]This macro can be used in the ScriptCase events and created button and may return values/process after the execution. [TABLE=“border: 0”]
[TR]
[TD=“width: 15%, align: left”]Option[/TD]
[TD=“align: left”]Description[/TD]
[/TR]
[TR]
[TD=“align: left”]sc_exit()[/TD]
[TD=“align: left”]Returns to the previous application without display anything.[/TD]
[/TR]
[TR]
[TD=“align: left”]sc_exit(ok)[/TD]
[TD=“align: left”]Displays a window with an OK button adn returns to the previous application.[/TD]
[/TR]
[TR]
[TD=“align: left”]sc_exit(sel)[/TD]
[TD=“align: left”]Doesn’t display the window with an OK button and returns to the current application, repeat the application select.[/TD]
[/TR]
[TR]
[TD=“align: left”]sc_exit(ref)[/TD]
[TD=“align: left”]Doesn’t display the window with an OK button refresh data and returns to the current application.[/TD]
[/TR]
[TR]
[TD=“align: left”]sc_exit(ok,ref)[/TD]
[TD=“align: left”]Same of the sc_exit(ref) function; however, display the OK button.[/TD]
[/TR]
[TR]
[TD=“align: left”]sc_exit(ok,sel)[/TD]
[TD=“align: left”]Same of the sc_exit(sel) function; however, display the OK button.[/TD]
[/TR]
[/TABLE]

					This option is only valid for Form and Control Applications.

[TABLE=“border: 0”]
[TR]
[TD=“width: 15%, align: left”]Opton[/TD]
[TD=“align: left”]Description[/TD]
[/TR]
[TR]
[TD=“align: left”]sc_exit()[/TD]
[TD=“align: left”]Doesn’t complete transactions in database.[/TD]
[/TR]
[TR]
[TD=“align: left”]sc_exit©[/TD]
[TD=“align: left”]Commit pending transactions.[/TD]
[/TR]
[TR]
[TD=“align: left”]sc_exit®[/TD]
[TD=“align: left”]Rollback pending transactions.[/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[/TABLE]

@nonkelmike

Thank you very much for your clear explanation. It really helps!

Hi! I implemented this solution for the insertion of a record.

I would like to use a similar strategy when the form is updated. I adapted the code and inserted:

// onAfterUpdate
// Flag if record has been successfully deleted
[session_updated] = True;

However, the application keeps on loading and neither exits nor gives an error. Any suggestions?