B510
Posts: 0
Joined: Wed Jun 04, 2014 2:17 pm

how to check whether the userid already exists or not?

Dear All,

I am new with this, I have created my own user table, how to check whether the userid already exists or not?

My current position is now on the event click of "Register" button and don't have any idea on how to do this?

please help

thanks a lot in advance

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

how to check whether the userid already exists or not?

Hi Winanjaya.

You can use "query" service for this purpose.

In "where" clause you can use following:

precode

{"userid": "hereIsYourUserIdYouWantToTest"}

/code/pre

Then you need invoke this service before start add user into DB.

Also you need to add "Success" event handler to these datasource with following JS:

precode

var isUserExists = data.length > 0;

if(isUserExists)
alert("userExistsInDB")
else
alert("userNotExistsInDB");

/code/pre

Note: you should replace these alerts with code you need in accordance to your app logic.

Regards.

B510
Posts: 0
Joined: Wed Jun 04, 2014 2:17 pm

how to check whether the userid already exists or not?

Hello..

Thanks, it goes to error event.. how to show its error?

B510
Posts: 0
Joined: Wed Jun 04, 2014 2:17 pm

how to check whether the userid already exists or not?

it return "Bad request" ...
what does it meant? ..what should I do?

please help.. thanks

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

how to check whether the userid already exists or not?

Winanjaya,

Please provide us information about how you set this "where" clause. Screen shots could help a lot.

In common use you should add in following way:

1 Open datasource mapping on request tab.

2 Find "where" request parameters and click "Add JS/Edit JS" button. http://prntscr.com/3ps6w8/direct

3 JS editor appears. Populate it with folowing JS code: http://prntscr.com/3ps84o/direct

precode

//Note you need replace this "534c7e16e4b02ae4f9496fc1" with ID you need.
var objectId = "534c7e16e4b02ae4f9496fc1&quot

var whereObject = {"_id": objectId};

return JSON.stringify(whereObject);

/code/pre

Regards.

B510
Posts: 0
Joined: Wed Jun 04, 2014 2:17 pm

how to check whether the userid already exists or not?

Thanks,
in my case .

var objectId = "txtUsername";
var whereObject = {"username": objectId};
return JSON.stringify(whereObject);

does objectId is the name of the object? .. or where can I find the object id info?

B510
Posts: 0
Joined: Wed Jun 04, 2014 2:17 pm

how to check whether the userid already exists or not?

Ok..

but how to get the value of the txtUsername ?

B510
Posts: 0
Joined: Wed Jun 04, 2014 2:17 pm

how to check whether the userid already exists or not?

I got it :) .. thank you, you save my time

var objectId = Tiggr('txtUsername').val();
var whereObject = {"username": objectId};
return JSON.stringify(whereObject);

Return to “Issues”