This topic is locked
[SOLVED]

 Works for Normal Edit but not Inline Edit

10/12/2020 5:34:18 AM
PHPRunner General questions
S
Steve Seymour author

Hi,
I have some code in the Before Edit event which checks if a value is changing from Due to Serviced, if it is, it calculates a new service date depending on the service frequency.
/

1 BOOKED

2 DUE

3 SERVICED

4 CANCELLED

5 CONTACTED

6 QUOTED
if old service_status_id was DUE, and being change to serviced, then update the next_service_date by the frequency_contract value

/
if (($oldvalues["service_status_id"] == 2) AND ($values["service_status_id"] == 3)){ // was DUE - changing to SERVICED

//update next due date

$date=date_create($oldvalues["next_due_date"]);

date_add($date,date_interval_create_from_date_string($values["frequency_contract"]));

$new_service_date = date_format($date,"Y-m-d"); // has to be in this format to work

$values["next_due_date"] = $new_service_date;
}
return true;
This all works as expected in "Normal" edit mode (Edit page) but doesn't work with inline edit.
I understand that this event is supposed to fire for both edit and inline edit.

Has anyone had and solved similar issues with inLine edit not working as expected ?
The edit of the field that changes DUE to SERVICED get updated, but the calculated date doesn't change which

makes me suspect that this event isn't being called at all ?
Steve.

Sergey Kornilov admin 10/12/2020

A couple of things to check.

  1. If you have a different set of fields on regular Edit and on the Inline Edit it may cause this kind of issues. For instance, if the field "frequency_contract" doesn't appear on the Inline Edit page then $values["frequency_contract"] will be empty and your calculations won't work.
  2. If you need to make sure that this is event is executed in the inline mode you can send something to the output from that event. You can also do the same to verify that your calculations are correct.

S
Steve Seymour author 10/12/2020



A couple of things to check.

  1. If you have a different set of fields on regular Edit and on the Inline Edit it may cause this kind of issues. For instance, if the field "frequency_contract" doesn't appear on the Inline Edit page then $values["frequency_contract"] will be empty and your calculations won't work.
  2. If you need to make sure that this is event is executed in the inline mode you can send something to the output from that event. You can also do the same to verify that your calculations are correct.


Thank you Sergey.

Yes the inline edit is on the list page which has a limited number of fields. (frequency_contract) is not on the list page - only the edit page.

That would explain why it doesn't work for inline edit - if only the displayed fields are passed.

I'll have to find a work-around. Possibly call a script to do it in the after_edit event.
Steve.

S
Steve Seymour author 10/12/2020



Thank you Sergey.

Yes the inline edit is on the list page which has a limited number of fields. (frequency_contract) is not on the list page - only the edit page.

That would explain why it doesn't work for inline edit - if only the displayed fields are passed.

I'll have to find a work-around. Possibly call a script to do it in the after_edit event.
Steve.


SOLVED.

The parameter $oldvalues contains all the fields of the record. As that field is not changing I can use the $oldvalues["frequency_contract"] in the calulation.