Field value being nulled - sometimes! - when passed to update query

I've hit a really weird problem. Maybe I've missed something obvious (hopefully!), or maybe it's a bug. Any ideas on how to fix it would be really appreciated!

I have an update/insert SQL query 'PartnerU', which uses {{ parseInt(Input_PartnerID.value) }} as the 'partner_id' column value. Input_PartnerID is a field on a form.
In my submit button script, I call another query to check for overlapping records (they have date ranges) and if all is well, I trigger the update query PartnerU.

When it's triggered from the submit script, it fails, saying that I've attempted to insert a null value into partner_id. Logging the value parseInt(Input_PartnerID.value) to the console at each step in the script shows that it is always a valid integer value, never null. I'm stumped as to why the query is seeing null.

To test, I added another button and had it trigger the check query followed by the update query, without any control logic around the check. It works fine, updates the correct record in the database without any issue.

What could be causing the update query to see a null value when it's called from the first script, given that the field value is very definitely not null ?!

Full submit script is this:

var c=999;
console.log('start: PID=' + parseInt(Input_PartnerID.value));  // shows 7

await PartnerOverlapCount.trigger({
  onFailure: function(data) {
    console.log('PartnerOverlapCount failed!');
    console.log(PartnerOverlapCount.error);
    console.log(data);
    text_Status.setValue('<P style="color:#ff0000"><b>Unable to check for overlapping records; unable to save!</b></p>');
  },
  onSuccess: function(data) {
    console.log('PartnerOverlapCount okay');
    console.log(data);
    c = data.ct[0];
    console.log('Overlap count=' + c);
  }
});

console.log('before update: PID=' + parseInt(Input_PartnerID.value));     // shows 7

if (c == 0) {
  console.log('Calling PartnerU');
  PartnerU.trigger();
} 
else {
  text_Status.setValue('<P style="color:#ff0000"><b>Cannot save! Record validity period overlaps another record for this partner.</b></p>');
}

console.log('after update: PID=' + parseInt(Input_PartnerID.value));    // shows 7

Here's what we get on the console:

10:48:09 PartnerOverlapCount ran successfully (0.379s).
PartnerOverlapCount
10:48:12 start: PID=7
10:48:12 PartnerOverlapCount okay
10:48:12 {ct: Object}
ct: Object
0: 0
10:48:12 Overlap count=0
10:48:12 before update: PID=7
10:48:12 Calling PartnerU
10:48:12 after update: PID=7

The reduced submit script, which succeeds:

await PartnerOverlapCount.trigger();
await PartnerU.trigger();

Hey @JeffT! Super weird.

Sounds like some sort of race condition potentially that's honestly probably best debugged live. OR could I step into your app? If this sounds okay with you, could you DM me (by clicking on my name and then Message) a link to your app? :slight_smile:

Hi @Victoria,

I messaged you the app link a while back; did you get it and do you have any clues as to why my app's behaving strangely?

Thanks!

Hey Jeff! I sent you an email, but realized I never replied here! Just wanted to make sure you're not still blocked.

As a quick note, it definitely looks like the form is being cleared before the information is being submitted. This generally happens with complex submit logic. You could also have an event handler that runs on submit/button click to first run the update query. Then, you could add an event handler to that update query to run all the other logic you need to. Would something like that work for you instead?

That's strange; I've not seen any email from you, that's why I checked you again here!

If your email was more detailed, perhaps you could re-send or send as a message here, please? I'm puzzled why 'complex' (really? it's only a few lines of code!) submit logic causes the form to get cleared. There's nothing in my code that would clear it and ReTool wouldn't clear the form on a basic submit, so that's a pretty weird effect.

I'll try chaining the event handlers onto queries in whatever ways I can and see what happens.

I'll let you know how I get on...!

Thanks,

J.

Hi Victoria,

I've changed the app so that the 'save' button calls a query to check for overlapping time periods and if that query returns no problems, its 'success' actions trigger the update query, PartnerU. The check works fine and I see that PartnerU is triggered, but the record is not saved or inserted; the database table isn't changed at all!

If I run PartnerU on its own, it updates the records just fine.

Definitely still blocked... Help!

Current version of the app is here: Retool

@victoria, anyone @ retool?

@JeffT @victoria I am facing the same issue. I have a form in that i have date input field and some other fields sometimes the date field return null don't know why that date field is mandatory so user must select value to submit the form.

Hello @JeffT and @tkumawat!

Unfortunately Victoria is no longer part of the team and is currently traveling the world!

In the meantime, I can try my best to sort out these issues. That's very odd that PartnerU is able to update records fine when run on its own but not when it is triggered following a successful call of the overlap check....

Do you get an error message or anything in the debugger when PartnerU is triggered by the overlap check query? Could you provide any screenshots or potentially drop into our Retool office hours on discord to do some live debugging?

If the query works fine alone, one option could be to use a retool workflow to trigger the queries instead of trying to chain them inside of the onClick/onSuccess event handlers.

For the issue of date inputs sometimes returning null even when a value is submitted, I am pretty stumped on that. If you could provide screenshots of the error and the submit query/input component I can better troubleshoot :sweat_smile: