When the program automatically creates a new database, it sets all currency fields to the currency used by the system.
Script Group
Program
Event
Action
You may need a currency other than the default one, and changing it would mean editing every single currency field.
This example works directly on the field settings.
WARNING. MISTAKES CAN CAUSE THE PROGRAM TO MALFUNCTION OR FREEZE. SO BE CAREFUL AND TRY IT ON A TEST DATABASE FIRST.
We’ll work directly on the so_fields table, which manages all the fields of the database.
{"ND":2,"CU1":"it-IT","CU2":"EUR","FCO":0,"def":""}
Above is the dictionary that holds the settings of a currency field. The first value, CU1, is the so-called culture info code; you can find the full list at this link. The second code is the currency code, and you can find the full list at this link.
By changing these values we can change the currency of the field.
t = database.getsql("SELECT * FROM so_fields WHERE fieldtype=5")
nrows = t.countrows()
rows = t.getrows()
for i = 1, nrows do
parametri = rows[i].getvalue("param")
parametri = string.gsub(parametri,"it-IT","en-US")
parametri = string.gsub(parametri,"EUR","USD")
database.setsql("UPDATE so_fields SET tid=" .. tostring(utility.tid()) .. ",param='" .. utility.convap(parametri) .. "' WHERE gguid='" .. rows[i].getvalue("gguid") .. "'")
database.addsyncbox("so_fields",rows[i].getvalue("gguid"))
output.print(parametri)
end
As the example shows, we first retrieve from the so_fields table all fields of type 5, that is, the currency fields. Then, using Lua commands, we replace the current values with the desired ones and save them to the database.
This forces all the fields to be updated.
Given the kind of operation, close the program and open it again so the new values are loaded.
