Database Values as NodeJS Parameters
Posted: Wed Jun 07, 2023 2:49 pm
We use a SwitchScript to save values in private data fields of the job and this script works perfectly well as a legacy script.
We now rewrote it as a NodeJS SwitchScript and it also works like a charm, but NOT when a parameter value for the script comes from a variable that fetches a value from a Database Connection like this:
(the hashtags are placeholders for privacy reasons, this part is just an example and works 100%)
The NodeJS SwitchScript fetches the parameters like this:
ALL parameters that I pass to this script work fine, except those that are being read from an external database.
Ofcource, when I view the value of exactly this variable within Switch it can be read from the database within a second, so I get the correct values. But the NodeJS script gets passed an empty string in all these cases. I assume that the NodeJS script does not await the final value, even though there are "awaits" right before the flowElement.getPropertyStringValue() calls.
I even forced the script to wait 20 seconds right at the start, but this didn't help either. (Wouldn't be a solution anyway, because I can't just make all jobs wait. But it was worth a test:
But as I said: This waiting didnt help either. I am quite sure that the NodeJS script gets empty strings even though the Database-Connection variables should have real values.
Do I miss anything?
Can anybody give advice?
Thank you very much
Daniel
We now rewrote it as a NodeJS SwitchScript and it also works like a charm, but NOT when a parameter value for the script comes from a variable that fetches a value from a Database Connection like this:
Code: Select all
[Database.Text:SQL="SELECT #columnName FROM #tableName WHERE #columnValue = '[Job.PrivateData:Key="adID"]'",Connection="FileMaker-Database"]
The NodeJS SwitchScript fetches the parameters like this:
Code: Select all
tempKey = (await flowElement.getPropertyStringValue("key1")) as string;
tempValue = (await flowElement.getPropertyStringValue("value1")) as string;
Ofcource, when I view the value of exactly this variable within Switch it can be read from the database within a second, so I get the correct values. But the NodeJS script gets passed an empty string in all these cases. I assume that the NodeJS script does not await the final value, even though there are "awaits" right before the flowElement.getPropertyStringValue() calls.
I even forced the script to wait 20 seconds right at the start, but this didn't help either. (Wouldn't be a solution anyway, because I can't just make all jobs wait. But it was worth a test:
Code: Select all
import { setTimeout } from "timers/promises";
await setTimeout(20000);
await job.log(LogLevel.Info, "waited 20 seconds... maybe we get all database values now?");
Do I miss anything?
Can anybody give advice?
Thank you very much
Daniel