Trying to set a Screen Field on a Data View from an async function

Hello!

I am trying to set a Screen Field named ‘Total’ on a Data View using data returned from a server-side function, but without success.

It seems that updating a Screen Field on a Data View from an asynchronous callback doesn’t work the same way as on a standard Form Field.

Could you tell me how to properly set the field value for a Screen Field in this context?

Here is my client-side function:

function CalculateTotal(five, context, result) {
    five.field.Total = 9999 // Example demonstrating that the field name is correctly spelled and works synchronously
    
    const variables = {};
    variables['var1'] = five.variable.var1;
    const sender = five.sender();

    five.executeFunction('CalculateTotalServer', variables, null, '', '', function (res) {
        if (!res || !res.serverResponse) return;

        const data = res.serverResponse.results;
        if (data) {
            const serverData = JSON.parse(data);
			// The server returns the correct value, but the UI does not update the Screen Field here
            sender.dataManager.setValueByName('Total', serverData.TotalSolde);

        }
    });
    return five.success(result);
}

Thank you!
Jean

Hi Jean,

The problem is that the dataManager property is not avaible in your version.

Scenario 1:

In the coming version, you will be able to modify a screen field by clicking on another screen field that executes a server function. Ex: if I have a screen field button ‘Update Total Price’.

Scenario 2:

If I am not mistaken, you want to click on a button on a data view row, then modify the screen field above. If so, I have notified the Development team about this scenario.

And just to give you a heads-up on how I am updating the field, this is the function I am using in scenario 1, and hopefully, when the new changes are made, this will be the same for scenario 2.

function CalculateTotal(five, context, result) {

const variables = {};

const field = five.sender();

const dataManager = field.dataManager;

five.executeFunction('CalculateTotalServer', variables, null, '', '', function (res) {

    if (!res || !res.serverResponse) return;

    const data = res.serverResponse.results;

    if (data) {

        const serverData = JSON.parse(data);

        dataManager.setValueByName('Total', serverData.TotalSolde);

        dataManager.setModifiedField(field.formField.key());

        field.refresh();

    }

});

return five.success(result);

}

Regards,

Elton S

Thank you Elton.
Yes I have a list of accounts receivable, and based on the selection of another screen field, I want to display the sum of the amount due. Do you have any idea when the new version with this feature will be available?
Thanks again for your help!

Jean

Hi Jean,

We don’t have a confirmed date yet, but it should be available soon. We’re currently carrying out thorough testing to make sure both the existing and new features work smoothly and are free of bugs.

Regards,

Elton S

1 Like

Thanks for the update!

Just to clarify one point: modifying the Screen Field actually works very well in my current version when triggered by another Screen Field or a button!

My issue is specifically when calling the function from the ‘On Show’ event of the Data View. I would like the total amount due to be calculated and displayed automatically as soon as the view opens, and then recalculated when a user changes a selection.

I’ll use a button as a workaround in the meantime.

Best regards,

Jean

Hi Jean,

Thank you for the extra clarification. I will update the team about this scenario.

I will keep you posted on any updates.

Regards,

Elton S

1 Like