This topic is locked
[SOLVED]

 Add Page Before Process Script

1/31/2015 8:31:47 AM
PHPRunner General questions
G
GregJ author

The little script below lives in my Orders - Add Page Before Process Event. It's just a counter which runs perfectly when the Add button is clicked, the projnum increments in the ProjNums table. But then, the script appears to run again when I click the Save button to save the new Orders record, incrementing the projnum a second time. The Orders and ProjNums tables are not connected in any way. ProjNums has only two columns, groupid and projnum with no auto-increment fields. The same double increment happens if I set up two similar tables in a sandbox outside my main project.
What's going on? Is this a bug in PHPR 8 or am I missing something?
global $dal;

$tblProjNums = $dal->Table("ProjNums");

$groupid=$_SESSION["groupid"];

$sql = "UPDATE ProjNums SET projnum = projnum+1 WHERE groupid = '$groupid'";

$rs = CustomQuery($sql);

Sergey Kornilov admin 2/3/2015

This behaviour is by design, BeforeProcess event is executed when Add page is loaded the first time and then again when Add page is loaded again after you click Save.
Move this code to BeforeAdd or AfterAdd event.

G
GregJ author 2/5/2015

OK, the ideal spot is BeforeProcess in my case. I can't imagine why I would ever want that script to run twice but I have changed things around and put it in BeforeAdd where it is working now. Thanks for the heads up Sergey.