In my application, I’m experiencing the following glitch:
When I create a new Payment record, it is created fine, but the Payment Name does not appear in the list on the left (it shows up blank - see screenshot).
However, when I either edit this record right away and save OR go to any other page of my application and then return to the Commission Payments page, the Payment Name appears just fine. Five doesn’t return any errors.
The “Payment Name” is an automatically created (read-only) concatenated field that consists of the Payment Date and the name of the person, who received the payment.
The Form runs the Function below on “Do Complete” event.
The Function runs two Queries. The first Query is the one that generates data in the Payment Name field.
function PaymentNameUpdateFunction(five, context, result) {
// Execute the first update query
let queryResult1 = five.executeQuery(‘PaymentNameUPDATEQuery’);
// Assuming queryResult returns an object with a property ‘PaymentName’
if (queryResult1 && queryResult1.PaymentName) {
five.field.CommissionPayments.PaymentName = queryResult1.PaymentName;
}
// Execute the second update query
let queryResult2 = five.executeQuery('iUserKeyInCommPaymntsUPDATEQuery');
// Assuming queryResult returns an object with a property 'iUserKey'
if (queryResult2 && queryResult2.iUserKey) {
five.field.CommissionPayments.iUserKey = queryResult2.iUserKey;
}
return five.success(result);
}
Below is the first Query in the function above:
UPDATE CommissionPayments
INNER JOIN Users ON CommissionPayments.UsersKey = Users.UsersKey
SET CommissionPayments.PaymentName = CONCAT(CommissionPayments.PaymentDate, ‘-’, Users.UserName);
How to make the name of the new record appear right away, as soon as the new record is saved?
Apologies for not replying sooner to your issue, I just imported your application to have a look at this for you.
I must say, thank you very much for the detailed description of your form setup!
It isn’t displaying in your list before refreshing because when you are making changes to the database, Five doesn’t know that you have updated the data in separate queries in your Do Complete function.
You need to use the table events for what you are trying to achieve using context.new. This way Five knows you are updating values on the form and sends them back to the UI.
To make this work, perform the following:
Delete the PaymentNameUpdateFunction from the Do Complete event on the Commission Payments form. Note: You don’t need to delete the function just delete it from being attached to the Do Complete event.
Add the function I have added below. Note: you will notice the records parameter is used on the queryResult.
function UpdateNewCommissionPaymentName(five, context, result) {
let queryResult1 = five.executeQuery('SELECT UserName FROM Users WHERE UsersKey = ?', 1, context.new.UsersKey);
context.new.PaymentName = context.new.PaymentDate + '--' + queryResult1.records[0].UserName;
return five.success(result);
}
Attach this function to the Do Before Insert event on the CommissionPayments table.