Goal:
I have a list widget that lists records from my database. When you click on a row, it opens up another retool page/app and appends a unique identifier to the application URL. Example https://brobb07.retool.com/apps/ea07f360-aee2-11ef-95d9-630221aea7bc/Update%20Company?company_number=000000000000009
I am extracting the company_number=000000000000009 query string so that I can use 000000000000009 to run an API query against my database and populate the record values on the form.
I add a query to to my page/application, set it to run manually (name is "query1" for the sake of testing)
Then I add a JS Code to execute the API in hopes of getting the data back and manually populating fields on my form.
For simplicity, I use the following code snippet to extract the query string from the URL and trigger my query.
// Define the parameter value
const url = new URL(urlparams.href);
const companyNumber = url.searchParams.get('company_number'); //value of 000000000000009
// Call the query and pass the parameter
query1.trigger({
additionalScope: {
comp_num: paramValue
},
onSuccess: (data) => {
//parse the data object
console.log("Query succeeded:", data);
},
onFailure: (error) => {
console.log("Query failed:", error);
}
});
Details:
The code snippet seems correct. When I tinker with the query I am seeing that either I get "all" records back from the table or an error. Basically it is not accepting my parameter. I tried using the URL parameters but no matter what I do, it fails. Can anyone tell me what I need to modify in the query?
Based on that code snippet, it looks like paramValue isn't defined anywhere. If you want to pass the companyNumber to query1, you'll need to modify the Javascript so that the additionalScope looks like this:
additionalScope: {
comp_num: companyNumber
},
Then, you also need to modify query1 to use the additionalScope param. You can replace * in your query1 with {{comp_num}}. {{comp_num}} will show up in query1 as red/not defined, which is the expected behavior. It'll get defined when you run the setCompNumVariable Javascript query
Thank you Tess for the follow up. I think I am getting close. My JS code is as follows as a test
// Define the parameter value
const paramValue = '000000000000008';
Hi @Robbie_Williams Thanks for the update! It looks similar to this issue. Could you remove company from the base url and add it manually to your query?
@Tess Thank you Thank you Thank you! I am newer to the retool platform and for some reason I was on that one for awhile. That is a big hurdle to clear in my development. Very much appreciate your help!