I'm trying to get the the url data from uploadPDF and use it in within onSuccess. uploadPDF.data.url returns the previous result from uploadPDF instead of the new one. addAVDeviceWithPDF should only run once the uploadPDF is successful.
You can leverage async calls to make this a little cleaner and easier to debug. Try this.
const cutsheet = fileInput1.value.length
const newCategory = form1.data.category;
const newModel = form1.data.model;
const newWatts = form1.data.watts;
const newMake = form1.data.make;
if (cutsheet === 0) { // ** Almost always recommended to use === instead of == in JS
// I don't know what this section is for in general, so update as needed
await addAVDevice.trigger();
return false;
} else {
// Using await prevents the next line from running until the trigger is resolved.
// You can add try/catch blocks if you need error handling
await uploadPDF.trigger()
await addAVDeviceWithPDF.trigger({
additionalScope: {
deviceData: {
category: newCategory,
model: newModel,
watts: newWatts,
make: newMake,
pdf_url: uploadPDF.data.url
}
}
});
return true
}
Thanks @MikeCB that looks to be exactly what I need!
I got stuck on trying to use onSuccess. What is the correct use case for onSuccess when you can just use try/catch? Would it mainly be for running queries that don't rely on the previous trigger?
EDIT:
Sadly i'm still having issues with uploadPDF returning the previous url instead of the file url that was just uploaded.
Glad to hear you got everything working, @lpearl! I'm pretty sure the previous implementations weren't behaving as expected because variable references within a query don't automatically sync with the global context in order to improve performance. To override this default behavior, you can toggle on the "Keep variable references inside this query in sync with your app" setting: