This topic is locked

Field update in Master Page using UpdateMaster does not save to database

10/30/2025 13:34:31
PHPRunner General questions
C
chandoshi authorDevClub member

I have the following code that updates a field in master record when child table is edited.

var mPage = pageObj.getMasterPage();
if (mPage) {
mPage.findItem('PaidAmt').text(parseFloat(result['totAmt']).toFixed(2));
}

The code works as it should, but when I save the master record this values does not get saved to database.

Do need additional code in "Before Record Updated" to make this happen?

ChatGPT 10/30/2025

Yes, to ensure that the updated value is saved to the database when the master record is updated, you will need to perform a few additional steps. The code you provided updates the displayed value on the page, but it does not actually update the data in the database.

Here’s how you can do this:

  1. Update the Field in the Database in the "Before Record Updated" Event:
    You will need to capture the updated value in the "Before Record Updated" event of the master table and then set the new value to be saved in the database.

    You can achieve this by modifying your "Before Record Updated" event in the server-side code.

    Here’s an example of how you might do this:

    // In the Before Record Updated event for the master table
    function BeforeRecordUpdated($values, $where, $table) {
    // Assuming 'PaidAmt' is the field you want to update
    // and you have the updated amount stored in a variable
    $newPaidAmt = $_POST['PaidAmt']; // Capture the updated value from the form

    // Set the value to be updated in the database
    $values['PaidAmt'] = $newPaidAmt;

    // Return the modified $values array
    return $values;
    }

  2. Ensure the JavaScript Updates the Form Field Correctly:
    Make sure that your JavaScript updates the corresponding input field on the form so that when the form is submitted, the new value is included in the POST data.

    Your JavaScript code should look something like this:

    var mPage = pageObj.getMasterPage();
    if (mPage) {
    // Update the display value
    mPage.findItem('PaidAmt').text(parseFloat(result['totAmt']).toFixed(2));

    // Also update the input field
    mPage.findItem('PaidAmt').val(parseFloat(result['totAmt']).toFixed(2)); // This line ensures the form input is updated
    }

  3. Test the Workflow:
    After implementing these changes, test the workflow to ensure that the updated values are saved correctly when the master record is submitted.



By doing this, you ensure that the updated value in the user interface is also reflected in the database when the master record is saved.

C
chandoshi authorDevClub member 10/30/2025

The solution provided by AI as shown below does not work:

changed the code to save the value:
var mPage = pageObj.getMasterPage();
if (mPage) {
mPage.findItem('PaidAmt').text(parseFloat(result['totAmt']).toFixed(2));
mPage.findItem('PaidAmt').val(parseFloat(result['totAmt']).toFixed(2));
}

Updating PaidAmt before Record Update as follows:
$newPaidAmt = $_POST['PaidAmt']; // Capture the updated value from the form
$values['PaidAmt'] = $newPaidAmt;

fhumanes 10/30/2025

Hello,

I don't know if this example will help you. I think it's similar to what you're trying to do.
As you will see, it is from previous versions, but perhaps it can be used as a guide.

https://fhumanes.com/blog/guias-desarrollo/guia-7-phprunner-sincronizar-actualizacion-entre-maestro-y-detalle/

Greetings,
fernando

C
chandoshi authorDevClub member 10/30/2025

Hi Frenando,

I could not find any code I could use from the solution link you provided. Can you point out to the code if ther is one that I could use.

As far as the solution from Chat GPT, ir seems to be using Rest API. This application does not have REST API activated.