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();