This topic is locked
[SOLVED]

 Before Record Updated Event

1/30/2020 9:52:41 AM
PHPRunner General questions
S
Steve Seymour author

Hi,
I have some code that is working well in the Before Record Update Event

It calculates a date and updates a field date depending on another field value.
This is all working as expected.

I want to allow users to update several records at once. This event (Before Record Update) doesn't seem to be available (doesn't fire) when Update Selected is used
Checking the manual, I found an example of updating multiple records on the list page, but this only allows for hard-coded value update and I need the user to select a value so that my date calculation can update another field.

(i.e. I need to update a date field depending on a user selected value) hence the need for Before Record Update Event)
Is there a way for Before Update Record Event to be called by the Update Selected method.
Steve.

A
acpan 1/30/2020

>> Is there a way for Before Update Record Event to be called by the Update Selected method.?
Yes. Before Record Updated event will run for all records selected with checkbox, verified on my PHPR 10.03(34262) latest build.
Maybe check how your code performs what you said:

"I need the user to select a value so that my date calculation can update another field"
The above is what PHPR can do by default. The part fails you may be the condition check before you do the calculation and assign the values (i assume you have condition check as i always do).
Depending on how you test the user selected value, your code that calculate and assign values may not get run in the event code.



// test conditions if there is a new value for user_selected_field

if ( isset($values["user_selected_field"]) )

{

// another condition check to make sure new value entered is different from existing value.

if ( $values["user_selected_field"] != $oldvalues["user_selected_field"] )

{

// assign values to be updated

}

}
S
Steve Seymour author 1/31/2020



>> Is there a way for Before Update Record Event to be called by the Update Selected method.?
Yes. Before Record Updated event will run for all records selected with checkbox, verified on my PHPR 10.03(34262) latest build.
Maybe check how your code performs what you said:

"I need the user to select a value so that my date calculation can update another field"
The above is what PHPR can do by default. The part fails you may be the condition check before you do the calculation and assign the values (i assume you have condition check as i always do).
Depending on how you test the user selected value, your code that calculate and assign values may not get run in the event code.



// test conditions if there is a new value for user_selected_field

if ( isset($values["user_selected_field"]) )

{

// another condition check to make sure new value entered is different from existing value.

if ( $values["user_selected_field"] != $oldvalues["user_selected_field"] )

{

// assign values to be updated

}

}



Thank you.

Support says that the BeforeUpdate Event is fired but with limited $values. In all my tests, I am unable to use the BeforeUpdate Event with Update Selected or Inline Edit, but it works perfectly for a Standard Edit page.

Even adding my own SQL to collect $oldvalues - doesn't.
Yes, I do checks.. and the fields in question is a required fields. It is as if the Before Update Event just doesn't get executed at all.
I will deal with it by adding a code snippet on the list page to create a form and do the update with an external php script. $sDebug doesn't help see what going on, echo's don't display, and print_r doesn't show, echo script alert also doesn't.

Quite frustrating when I can't break execution to check values.
Thank you for for consideration.

A
acpan 1/31/2020

Okay, just to let you know that on the PHPR version i stated above, i was able to update the selected records and run the events successfully on each records.
screencast
ACP

S
Steve Seymour author 1/31/2020



Okay, just to let you know that on the PHPR version i stated above, i was able to update the selected records and run the events successfully on each records.
screencast
ACP


Thank you ACP.

I will investigate further when I get a chance. At this time I just need a solution which I can achieve with external code.

Sergey Kornilov admin 2/1/2020

In case of Update Selected BeforeEdit event will be executed and $values array will contain the list of values, the user selected to update. This means a different set of fields will be available via $values array.
You also need to understand how to troubleshoot pages executed via AJAX. This article explains how you can see the output from pages executed via AJAX:

https://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm

S
Steve Seymour author 2/3/2020



In case of Update Selected BeforeEdit event will be executed and $values array will contain the list of values, the user selected to update. This means a different set of fields will be available via $values array.
You also need to understand how to troubleshoot pages executed via AJAX. This article explains how you can see the output from pages executed via AJAX:

https://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm


I have now resolved the issue I had...
I have service contracts that have statuses set by a time schedule contract_frequency (1 week, 2 weeks, 3 weeks 1 month 3 months, 6 months, 12 months..., a cron script checked the database table and then sets a service_status field to DUE.

When the service's have been completed (hundreds of services per month) Admin changes the service status to SERVICED. They needed the option to update multiple records at once.

Using the update Selected wasn't useable as the beforeUpdate event doesn't pass old values, and only passes the single field being edited. I needed to access The previous service date,

the contact_frequency, the existing service status (only statuses that are changing from DUE to serviced need to set the next service date.
I was able to place a select dropdown box on the list page, along with a custom button. Jquery obtained the service status from the drop down and passed it to the server event of the custom button.

In the service event, the table was queried to get existing values.. previous service date, contract_frequency, If the selected status was SERVICED, and the old service status was DUE, then all the selected records

were looped through with button->getNextSelectedRecord, a date calculation made with the existing service date and the contract_frequency to calculate a next service date. The records then updated as required.

Other changes in service status - simple updated the service status field. The after event was then used to refresh the page.