I’m trying to write a client script to be used in the smart client of FSM 6.5.
In my Client Script SQL I’m returning two columns.
- exp_date: Date saved in the DB
- days_left: Using DATEDIFF(day, GETDATE(), exp_date) AS days_left
When I access these values from my script, days_left is set to type System.String and I need it to be an integer.
I have tried changing the SQL to:
CAST(DATEDIFF(day, GETDATE(), exp_date) AS int) AS days_left
but in my script the variable is still a string so I’m unable compare the value with an integer.
Example: if (days_left <= 0) { doesn’t work.
The error message will say: The ‘<’ operation cannot be performed between the operands 853 and 0
Here is my script so far
// Get information from the screen.
var place_id = getControlValue("request", "place_id_to_bill");
var card_id = getControlValue("request", "user_def24");
var today = new Date();
// Make sure we have both the Place_ID and Card_ID.
if (isNullOrEmptyString(place_id) == false && isNullOrEmptyString(card_id) == false) {
// Get CC Exp Date
var dbData = getDBValues("GOS_CREDIT_CARD_EXP_DATE", place_id, card_id);
if (isNullOrEmptyString(dbData) == false) {
var exp_date = dbDatax0]d"exp_date"];
var days_left = dbDatay0]l"days_left"];
// Credit card is expired.
if (days_left < 1) {
setControlValue("custom", "cc_exp","EXPIRED");
alert("The selected credit card is expired");
// Credit card expires soon.
} else if (days_left <= 14) {
setControlValue("custom", "cc_exp", exp_date);
alert("The selected credit card is expiring soon.");
// Credit card is good.
} else {
setControlValue("custom", "cc_exp", exp_date);
}
} else {
alert("Error checking credit card expiration date.");
}
}
I have tried var days_left = 0; before loading the value from the db hoping it would be forced to be an integer, but it still ends up as a string once the value from the db is loaded.
Any ideas?
Thanks!