Working with Console Log

I understand that Console.log is in JavaScript but I want to use it in MySql code.

So I have tried to capture a value in MySql code with:

{{ ( console.log(CCNT1.value) }};

This does not work.

What is the syntax for using Console.log in MySqk code?

Mike

Hello @mdsmith1!

If you want to view the results of a Query to a MySQL Database/Resource, you should be able to do this in the Query view panel. Next to the 'Save' button there is a 'Preview' and the results of the query will appear at the bottom of the query panel.

You can add in a console.log to the transform results box below the query inside the query panel as well.

You can also set a table to have its source be the MySQL query, then run console.log(table1.data) either inside of {{ }} or in a JS Query.

Hope this helps! :saluting_face:

Jack:

Here is what I get.

I have tried the transformer entry with console.log(@TTax) and console.log(@TTax.value) and both generate the same error message.

Mike

Hey @mdsmith1,

Thank you for sharing the screenshot with the mark up!

I believe the error might be coming from the @ symbol you used to define and save the TTax variable.

Let me experiment around and see if there is a work around for saving that value without the @ symbol or if that is a bug which Retool needs to fix :sweat_smile:

I had not seen anyone use @ or := in SQL so I just learned that those are both valid and being used properly. In the transformer result, I see there is a red underline. If you hover your mouse over that, is it giving you the same error?

I also see on line 18 you set the variable TOTAL to be equal to @TTax, maybe you can console log that variable?

I might need to see the whole query or a boiled down version of the query to replicate it and test out how we can get that summation of tax to appear in a console log!

Hi Jack:

I have tried leaving out the @ symbol and that causes other errors that prevents to assignment of values to the variable.

I have tried using TOTAL and that causes errors in the Transformer section.

Here is a boiled down version of the code.

update Invoices01c set TAX = QTY * PRICE * TAXRATE/100 ;
 
update Invoices01c set TOTAL =  (QTY * PRICE) + TAX  ;

SELECT @TTax:=SUM(TAX) FROM Invoices01c ;

 update Invoices01c set TOTTAX = @TTax ;
 
 SELECT @TTotal:=SUM(TOTAL) FROM Invoices01c;

 update Invoices01c set GRTOTAL = @TTotal ;

update Invoices01c set GRTOTAL2 = @TTotal2 ;

Mike

Hi Mike,

Thank you for the details and sharing the query!

It looks like we should be able to view the variable you are creating from the results tab of the MySQL query.

Are you able to run the query and see in the output, under 'data' the @TTax variable?

From the Success query event at the bottom of the query, we can run a separate Javascript Query that console logs the variable from TaxFillTableInv.data to get @TTax to show up in the console!

The JS Query will have access to the 'TaxFillTableInv' and you can key into the .data property with something like TaxFillTableInv.data['@TTax']

I was poking around the forums and found this post :grin: you will want to do pretty much the same thing but instead of the Action being 'set to local storage' you would select 'Run Script' and console.log(TaxFillTableInv.data['@TTax']).

Let me know if that works!

I just tested it out, and the editor has a yellow line under the query name, on hover it says 'that query is undefined' but this is a false bug and it should work fine. As the query result and its data are created when the query runs!

Jack:

I will nor be able to get back to you for 2 weeks.

I will contact you at that time.

Mike

1 Like