Hello,
I am trying to use an async function in the calculated values of SurveyJS. The async function itself works as I have verified that it properly outputs the correct values to console, however, that value is not reflected in SurveyJS when using the calculated value. I am assuming this is due to the survey being displayed/rendered before function finishes. While looking through other tickets I found a ticket quite similar to my issue, though no solution came out of it (https://surveyjs.answerdesk.io/ticket/details/t14415). I have attached a few images that should help visualize the issue. When running the survey, the {lastUpdated} is null, though, console says it is not. Not sure whether I am missing a SurveyJS setting when using async functions but I have added that the "lastUpdated" function is async when registering it to the FunctionFactory.
JavaScriptconst lastUpdated = useCallback(async() => {
try {
const res = await axios.get("{URL}", {
params: {
userID: tokenPayload.sub
}
})
console.log(JSON.parse(res.data.body).Item.lastUpdated);
return JSON.parse(res.data.body).Item.lastUpdated;
} catch (error) {
console.log(error);
return "Never";
}
})
FunctionFactory.Instance.register("lastUpdated", lastUpdated, true);
Thank you.