Hi,
I have been having the hardest time doing something that seems to be
fairly straightforward. I have a MS SQL Server table with a primary key
having a Servoy identity. While printing labels I need to temporarily
create some records. In order to have no PK issues and for other
reasons I want to create those temporary records with negative
numbers.
The way I planned it was with a global field (g_neg_acc_order_id) defined
as an integer (or number). Through an SQL query I define NextNegNum
to be the number I want to assign to the global.
globals.g_neg_acc_order_id = NextNegNum
I know that NextNegNum is correct through the debugger. But I get this
error message whether I define the global as Number or Integer:
java.lang.IllegalArgumentException: Setting global with name
‘g_neg_acc_order_id’ / type ‘INTEGER’ with value of wrong type
JSDataSet:size:1,selectedRow:-1 (NumberIpoxCases, line 56)
Setting the primary key to the value of the global is not a problem. And
it all works the first time around (setting the global to -1). But thereafter
I can’t get the global to decrement. It is late and I am probably doing
something really stupid but I would appreciate any help ![Sad :(]()
please give me more code how you make that NextNegNum
because what it seems that you do is
var NextNegNum = databasemanager.exect…
globals.g_neg_acc_order_id = NextNegNum
NextNegNum is still a dataset not a number (NextNegNum.getValueAt(1,1) should do the trick
I awoke this morning with a shock, realizing what I had done
and then confirmed with your post. Part of it was the late
night but the other thing that really threw me was and is that
in the very same method I have used virtually the same code
and it works. Not once but twice! I have this code:
var NextNum_q = “SELECT TOP 1 idx_serial_num + 1 FROM ipox_master ORDER BY idx_serial_num DESC”;
var NextNum = databaseManager.getDataSetByQuery(controller.getServerName(), NextNum_q, null, 1);
idx_serial_num = NextNum;
(idx_serial_num is an integer field in the database)
On the other one I have a query like ‘select count(distinct
source) etc.’ I then set a variable = databaseManager.getDa..
And then set a global = to the variable. Both of those have
worked. I understand what is the correct way to do it and
why my earlier attempt to set the global variable directly
from the output of the query didn’t work. But can you tell me
why in the same method do these other ones work? I am
going to change them anyway to the .getValue(1,1) as
that seems more correct and foolproof. But I wish I had a
better understanding of why. I kind of wish the error
messages would give a slightly fuller explanation. I’m sure
when I have a better understanding of JavaScript I will find
that they are plenty verbose! But in the case that prompted
this post, I kept thinking it had something to do with my data
being wrongly matched (number/integer/string) because
(seemingly) I could ‘see’ what the output was in the debugger.
Thanks again so much for your help - really appreciate it.
John