Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

executeSQL refresh, update

Featured Replies

strange issue ... I am running an executeSQL to get a value and store that into a variable, then when the user goes to another record and runs the same executeSQL to get the new value it does not updating correctly.  Have tried ... adding a goto field, refresh window, commit record, goto another layout and come back and nothing seems to work.  more detail on the issue below ...

we have a INVOICE NUMBER field that gets a value that is incrementally higher than the last entry.  It is technically not a "serial number" but rather a text field (since the value has text and numbers in it) that users' can alter, so don't confuse it with a primary key.  Basically, when the user clicks into the INVOICE NUMBER field, we scripttrigger (on field enter) a popover to show the next value that the user should use, the value that we show the user is generated by an executeSQL (below) that is put into a merge variable for the user to see ... they can then type that value into the field if they want (or ignore the suggestion if they want also.  

The goal is for the the executeSQL command to finds the highest numerical value of the records in the table, then display that value + 1.  So if the last used invoice number (we call the field 'code') is SQ0014, then it would show the user SQ0015.

it works one time, but if you then go to the next record and click into the field again, the scripttigger still returns the same value, as if the last entered value never got stored into the database.  so, you open the database and click into the field and the merge variable shows SQ0015 ... then click into the field manually set the value, then goto the next record and click into the field again it still shows SQ0015 even though it has been used (it should show SQ0016, since that is the next available code).

by the way, at the begining of the scripttrigger and at the end, I clear the variable by using "set variable = """, so it should be resetting??

the setvariable command is as follows ... 

Let( 

[
assetcode =

 
GetValue ( 
ExecuteSQL (
"select code from ASSET where upper(code) like 'SQ%'"
; ""; "" ) 
;
ValueCount (
ExecuteSQL (
"select code from ASSET where upper(code) like 'SQ%'"
; ""; "" ) 
)
)
+ 1 ;
codenumber =  Filter ( assetcode ; "0123456789" ) ; 
] ;

"SQ" & codenumber
)

 

 what can i do to force the executeSQL to recalculate and not use the previously stored value?  Thank you in advance!!

Maybe break up all of those SQL calls into separate Set Variable Statements to debug it....

 

I'm shooting from the hip, but  try Something Like This
 

let

[

sql = "SELECT Code FROM Asset WHERE UPPER(code) like ? ORDER BY Code DESC"

myCode = getvalue(executesql(sql;"";"";"SQ%");1);

codeNumber = Filter(myCode;"0123456789") + 1

]

"SQ" & codeNumber'

)

A few things come to mind when doing this. If you're using numbers, create a separate field for Invoice number and then create a separate field InvoiceNumberText = "SQ" & Zero_Padding & InvoiceNumber

If you did that, you could simply query invoice number and sort descending to get the highest number
 

let(

[

sql = "SELECT InvoiceNumber FROM ASSET ORDER BY DESC"

];

getvalue(executesql(sql;"";"");1) + 1

)//end let

 

 

 

Edited by GisMo
"ORDER BY"

First off, it does not make sense to do two identical ExecuteSQL() calls, especially not an "expensive" one such as a LIKE.  So GisMo is on track: separate those out and use the Let() function for what is meant for: set va

As to why it is not working when going from record to record: it should work, but perhaps you have triggers enabled that get in the way?

 

 

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.