cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to compare database input with another input using case sensitivity?

122
Amethyst
Amethyst

How to compare database input with another input using case sensitivity?

hiii,

 

i have one javascript where i have one database service called to getWorkoutName.

Now i want to compare that workout names with the input by using case sensitive. here is a javascript code which is giving me database workoutnames. when i am giving input  "pushup" then result is showing already exist which is correct output but when i am giving an input "Pushup" then it's showing result as "Error executing service caseSensitive. Message :: TypeError: Cannot call method "toLowerCase" of null" instead of "already exist" so help me with this peoblem.

 

javascript:-

// result: INFOTABLE dataShape: ""
var result1 = Things["Database"].getWorkoutName({
workout_name: workout_name /* STRING */
});

var name1 = result1.workout_name;
var a = name1.toLowerCase();
var name2 = workout_name.toLowerCase();
if(name2.toLowerCase() === name1.toLowerCase())
{
result = ' Already exists';
}
else
{
result = ' Not Exists';

}

 

below are some snapshots of output please refer for better understanding;

 

3 REPLIES 3

Re: How to compare database input with another input using case sensitivity?

Hi @122 ,

 

Please refer the following Link .

 

Hope it Helps !!!

Re: How to compare database input with another input using case sensitivity?

I tried reproducing it, but it is working fine at my end. As per your error when you pass Pushup as an input and execute this service, one of the variable is coming as null and you are doing .toLoweCase() on that variable which is why it is failing. Can you apply some logger in this service to catch the culprit ? for example, before this line 

var name1 = result1.workout_name; add logger.warn("value of workoutname is" + result1.workout_name);

 

You can add more logger like above.

 

Also as per your code when you have already done this:
var name1 = result1.workout_name;
var a = name1.toLowerCase();
var name2 = workout_name.toLowerCase();

 

then why you are putting up if(name2.toLowerCase() === name1.toLowerCase()) in if block ?
as i can see you already have toLowerCase in variables so why you are doing toLowerCase again on the same variable ?

 

instead of this you can use if(name2 === a). I hope i understood your code in right direction, if there is something which I have misinterpreted please let me know.

Re: How to compare databasse input with another input using case sensitive?

"pushup" is a workout_name which is present in my database. Now i want to compare "Pushup" with database's "pushup". i just want to check spelling of the workout_name present in my database. so whenever i create a workout and giving that workout_name as "pushup" or 'Pushup" or "PUSHUP" i want it must show an error the Workout_name is already exist

Announcements

Check out the upcoming Expert Session: Understanding ThingWorx Navigate Licensing in Community "Customer Events" section.