NetTalk Central

Author Topic: Two Inserts  (Read 4091 times)

Stan

  • Newbie
  • *
  • Posts: 13
    • View Profile
Two Inserts
« on: June 19, 2007, 07:54:02 AM »
Hi All,

I have a Form for special Customer type (only called with Insert). Works fine.  However this Customer needs a additional record added to another file (many-to-many file).
In ValidateInsert Embed I have added hand code to do:
 
Access:File.Open()
Access:File.UseFile()
CLEAR(PRE:Record)
PRE:Field1ID = p_web.GetSessionValue('OneID')
PRE:Field2ID = p_web.GetSessionValue('TwoID')
Access:File.Insert()
Access:File.Close()

It works sometimes but not always (sometimes Field2ID is zero, the autonumber ID of the Customer record we are now inserting)?? 

Do I need a different embed?

Cheers,
Stan

Stan

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Two Inserts
« Reply #1 on: June 19, 2007, 10:03:13 AM »
Correction: Use to work in older version, never works now in 4.24 version.

My question should be:
How and where (what embed in Form) do I get the PRIMARY KEY ID (AutoInc number) for the current record being Inserted?

I would like to save it via p_web.SetSessionValue('PRE:RecordID', PRE:RecordID )

Cheers,
Stan

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: Two Inserts
« Reply #2 on: June 19, 2007, 11:39:37 PM »
Hi Stan,

Autonumbering is handled in 2 different ways.

a) the "classic" clarion way, Insert as form opens, then "update" when they press ok (or delete if they press Cancel). And

b) a "non fancy" way where the autonumbering is done right before the record is added (as they press ok).

The Web Server tries to use (b) because this makes for fewer problems if the user neither presses OK, nor Cancel. (which in a windows program is rare, but in a web program is really really easy.)
However he web server will use (a) when either;
i) there is a child browse on the form or
ii) you explicitly tell it to use (b). [ Advanced tab - "Prime Auto Inc" option]

But for you, there's a better solution.
Move your code to "PostInsert". That way the Autonumber will have been done for you, whichever approach it took.

Cheers
Bruce

mriffey

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
Re: Two Inserts
« Reply #3 on: August 13, 2007, 11:56:02 AM »
Bruce,

In a form where prime auto inc is checked, it doesnt appear that the CancelForm routine is being entered when the user hits the cancel button in INSERT MODE. In update, they do go through this routine.

Given that there's a p_web.delete in there, I would expect it to go through there on insert as well. Obviously it wont on a X click, but thats life.

Intentional? Bug? Aliens?

Mark

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: Two Inserts
« Reply #4 on: August 21, 2007, 07:38:57 AM »
Hi Mark,

If a file is set to AutoNumber, and prime auto-inc is checked. (Or if there is a child browse on the form). Then the Insert is done as the form opens, and the action is set to "Change".

Thus Cancel Form is called in the situation you describe, precisely because the Insert action is now Change.

However, if the action is still "Insert" then this routine is not called. (In 4.28 or earlier.) 

I have added code to 4.29 so that the CancelForm is also called on Insert.

Cheers
Bruce