Variable not recognized and setValue not working as expected?

  • Goal: update a variable based on additional scope.

  • Details: This is very straightforward thing that we have in our application. We have a table that includes a link. In the table, if you click on a button, it activates a QR code function that helps you download a QR.

This is the contents of the onClick event:

The function is very straightforward and looks like this:

// This function downloads a QR code based on the display id and whether it is a retirement or an assignment

// Trigger the REST query to get the base64 encoded QR code image data.
console.log("do I get here?")
await qr_code_link.setValue(link)
console.log("How about here?")
const response = await qr_code_api.trigger({});
const imgData = response.base64Data;

// Download the QR code image data as a file.
utils.downloadFile({
  base64Binary: imgData,
  fileName: `qr_code_${display_id}`,
  fileType: "png",
});

We have a variable defined as qr_code_link and when this is set, we trigger another function which creates the qr code which we then download.

Before any console.log is hit I see this error:



▶
Error:Cannot read properties of undefined (reading 'display_id')
retirements_table


▶
Error:Cannot read properties of undefined (reading 'display_id')
retirements_table


▶
download_qr_code failed (0.001s):Cannot create property 'setValue' on string 'xxxxxxxxxxxxxxxxxxxxxx'
download_qr_code

from download_qr_code response(download_qr_code)

▶
in download_qr_code.trigger()(download_qr_code)
additionalScope: {display_id: "xxxxxxxxxxxxxxxxxx", link: "https://xxxxxxxxxxxxxxxxxx/en/retirements/xxxxxxxxxxxxxxxxxxx"}
triggeredById: "retirements_table"
environment: "production"
in retirements_table clickAction event handler(retirements_table)
from user interaction

I omitted the private data but they are just strings the look like this "JFIJDJ3939302jJDJD".

We have not updated this app for a couple of months and this randomly stopped working. I also have no idea how to fix it.

If I manually define a link variable in my function, everything works. If I hover over the values in the additionalScope, I see what I would expect. I don't understand where this could be failing. Can someone please help?

I guess I had a variable also called display_id.

Retool couldn't distinguish between the display_id variable and what I passed in through the additional scope.

The error I'm seeing doesn't really explain why that was the issue and I don't know how the display_id was ever being called with "setValue" but that's okay.

I changed the name of the additionalScope variable to the_display_id and that resolved my issues.

2 Likes