- My goal: Show a detail page for a newly created record
- Issue: Detail page shows old data
- Steps I've taken to troubleshoot: A lot.
- Additional info: (Cloud or Self-hosted, Screenshots)
I just can’t seem to get this to work reliably. The way I have it programmed now, it will (mostly) return the correct detail page for the new entry, however, the first record created will hang. The only log on the first submission is “Success”. It seems to hang on [ insertVendorQuery.data.result[0].name ], but only on the first submission on page load/refresh. If you submit a second time it usually runs through and shows the detail modal. (ignore the extra indent, this is copied from the body of an if statement). This is in a JS query called when we click Save/Submit.
I’ve tried adding/removing awaits trying to understand what’s happening. The getVendorByIdQuery used to use the selectedVendorId variable, which works everywhere else but here, so I’m passing the ID as additional scope to avoid the issue of variables not propagating fast enough. I just need to RELIABLY create a new record and pass the new record ID onto getVendorByIdQuery.
I’m hoping I’m just missing something simple, since it’s been a while since I’ve been this deep in code, but I can’t seem to find a way to make this work. Can anyone point out what I’m doing wrong?
insertVendorQuery.trigger({
onSuccess: async () => {
// Get the newly created vendor ID and open detail modal
console.log('success');
console.log(insertVendorQuery.data.result[0].name);
// Set selectedVendorId to new row ID
selectedVendorId.setValue(insertVendorQuery.data.result[0].id);
console.log('selectedVendorId set');
// Trigger query with new ID
await getVendorByIdQuery.trigger({
additionalScope: {
vendorId: insertVendorQuery.data.result[0].id
}
});
console.log('getVendorByIdQuery finished');
// Increment refresh trigger to update tableview
vendorsRefreshTrigger.setValue(vendorsRefreshTrigger.value + 1);
console.log('vendorsRefreshTrigger set');
vendorFormModal.setHidden(true);
vendorDetailModal.setHidden(false);
}
});
Edit: Inserting a delay before reading insertVendorQuery.data made this much more consistent, but why? onSuccess should only be called once the query is done, should the data from the query not be available? If I leave the delay in (really would rather not), how long does the propogation take? If I set it to say, 100ms, would there be times where the propogation may take longer and cause the same issue?