Bill7270109
Posts: 0
Joined: Wed Dec 10, 2014 4:08 pm

Database if else query help

Hi first off thank you for the great service. The more I use it the more I’m learning.

I'm having difficulty with the below statement. It works but the problem is the entire code works. This is what I’m trying to do. I have a SLV and I’m matching it to the database. If it is an exact match then continue to the next service, if it doesn't match stop and alert them to try again. The issue is that it runs the entire thing. I don’t know how to stop it?

This is on my complete of my query service

(jqXHR.responseText = localStorage.getItem('groupid'));

if(true) {
alert ("GroupID in use Please try again");
}
else
Apperyio("groupIDNotFound").text("GroupID has been added please share.");
Apperyio("groupIDNotFound").show();

Thank you for your help in advance
Image

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Database if else query help

Hello,

You can check right away on the success event
1) Add JavaScript there
2) We are assuming you are receiving an object from the service,
then your check will be:
pre if (data[0].groupid == localStorage.getItem("groupid")){
.....
}/pre

Bill7270109
Posts: 0
Joined: Wed Dec 10, 2014 4:08 pm

Database if else query help

Hi Alena

Thank you so much for the speedy reply. I am new and im not really grasping how to implement this? You said to put this in the success event but im not sure what to type in place of the ..... and how it will know if it should stop because it did not find the exact match or proceed on. Do i also need to put something in the [0] or do i leave that alone? I did try it the way you wrote it adding a alert where you placed the .... and it did not work.

I'm sorry if im asking so many questions. I found so many of may answers by searching the forum but this one im having difficulty grasping.

Bill7270109
Posts: 0
Joined: Wed Dec 10, 2014 4:08 pm

Database if else query help

Just one other thing. The data that we are matching will be inputted by the user and unknown to use.

Bill7270109
Posts: 0
Joined: Wed Dec 10, 2014 4:08 pm

Database if else query help

Hi Alena

You have been a great help. But we still can not get it to work. Here is the complete workflow for what we are trying here.

We have a popup. In that pop up we ask for their username, password and Group ID. The other field in the popup we have not mapped yet. The submit button invokes the login service.

Our login before looks like this.
Image

On Success we are mapping local storage _id to userid, sessionToken to userSessionToken, and the username field to userName.

We are then invoking the query service. I think its here that we run into our problem.

Here is the before mapping and the java on the on the where.

Image

Java is
return '{"groupID":"'+value+'"}';

This is our success step. we are mapping running java and invoking service.

Image

Image

Java (Need help)

if (data[0].groupID == localStorage.getItem("groupid")){
alert ("Your ID was successfully registered Please Share");}

If what they entered into the Group ID (grpInput) field on the page matches anything in the groupID column in the DB display a alert. If there is no match invoke the create service "group_part3_add"..

Hope that made sense.

Bill7270109
Posts: 0
Joined: Wed Dec 10, 2014 4:08 pm

Database if else query help

Can anyone please assist? I know we are overlooking something simple.

Thank you.
Bill

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Database if else query help

Hello Bill,

We are working on it and will get back to you with the update.

Bill7270109
Posts: 0
Joined: Wed Dec 10, 2014 4:08 pm

Database if else query help

Don't be afraid to tell us that the way we are doing it is wrong. If there is a better way. We don't mind building this entire section of the app over again if that is what i it takes.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Database if else query help

Hello,

1) Add before next line
prereturn '{"groupID":"'+value+'"}';/pre

this line
prelocalStorage.setItem("groupid",value);/pre

2) Wrap your last snippet of code in the loop, so the final it will look like:
precodefor (var i=0;i<data&#46;length;i++) {
if (data&#46;groupID == localStorage&#46;getItem("groupid")){
alert ("Your ID was successfully registered Please Share");
}
}/code/pre

Bill7270109
Posts: 0
Joined: Wed Dec 10, 2014 4:08 pm

Database if else query help

Alena

Thank you for your help. We tried what you suggested and we cant seem to get it to work. When it finds the GroupID in the database it does generate the alert ("Your ID was successfully registered Please Share") but still moves on to the add service as shown below.
Image

How do we get that to stop if it does match an entry in the database and move on if it doesn't match.

Thank you for your help

Return to “Issues”