Random output when querying a Google Sheet file

Hello everyone,

I'm trying to code an app with the following speifications:

  • 1st screen = login in screen and lenguage selection (done)
  • 2nd screen = screen with two button "start work/stop work" (issue)

In the second screen pressing "start/stop work" starts the smartphone camera to scan a QR code on a printed sheet. This QR code reads all the informations printed on the sheet and sends them to a Google Sheet. I copied the Google Script code and the concept of CRUDQ from Google Sheet CRUDQ II

The Google Sheet file has the following columns: order number, raw material code, bag type, bag weight, required quantity, user who starts the work, date and time, user who stops the work, date and time, cleaning operation, notes, yeld, row index
Every order can be completed at different time (if required quantity = 60 an operator can start and make 20 pieces than stop; after n hours another operator can finish the remaing 40 pieces) so I need to query the table two times: with the first query I find max(P) with order number X, then I need to retrieve the entire row with P=max(P) to check if the order is already complete (criterion: quantity to produce < quantity produced) and if someone is doing the same job (criterion: if the variable "user who stops the work" is empty means that someone is doing the same job).

I have an issue querying the Google Sheet because I tried to scan the QR code 10 times and I obtained 3 different results (see the attached photo)

This is my block scheme:

I have a basic knowledge on programming so I can't figure out what I'm missing.
If there is a better way to do what I'm doing is all to the good.
Thank you in advance for your help.

Can you clarify if the problem lies with the qrCode scan result, or the google sheet query, from what you say it appears to be the scan output ?

I printed (and scanned) the same QR code to prevent any change/scan error from the PC screen.
I think the error lies on the query

And the scan of the same qrCode reliably returns the same output ?


is also likely to cause problems, because you are calling two queries "at the same time", therefore the results being returned may be one or the other. Call one query, get the output, then, and only then, call the second query and handles that result separately.

I changed the code as attached

I scanned the QR code 10 times and the results (get result) is always the same, no errors here.

With the other programming lenguage I am used to run the code "step by step" so I can't understand how the queries can be performed at the same time. I thought that the code execution was: global data, global sql -> CRUDAction -> web.get then global indice riga, global sql -> CRUDIIAction 2nd -> web.get but you are saying that CRUDAction and CRUDIIAction 2nd are performed at the same time.
How can I run them separately?

I tried to change the code based on this post but I'm obtaining the same random output. I think this method doesn't work because it uses " a clock component to wait for several seconds without blocking the device here" but I need too block the device and wait until the first query gets the result

Try like this:


No need for a wait, just do one thing AFTER the other :wink:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.