Page 1 of 1

how to check whether the userid already exists or not?

Posted: Thu Jun 05, 2014 12:32 am
by B510

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


how to check whether the userid already exists or not?

Posted: Thu Jun 05, 2014 12:57 am
by Yurii Orishchuk

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.


how to check whether the userid already exists or not?

Posted: Thu Jun 05, 2014 2:02 am
by B510

Hello..

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


how to check whether the userid already exists or not?

Posted: Thu Jun 05, 2014 2:10 am
by B510

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

please help.. thanks


how to check whether the userid already exists or not?

Posted: Thu Jun 05, 2014 2:36 am
by Yurii Orishchuk

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.


how to check whether the userid already exists or not?

Posted: Thu Jun 05, 2014 2:44 am
by B510

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?


how to check whether the userid already exists or not?

Posted: Thu Jun 05, 2014 2:46 am
by B510

Ok..

but how to get the value of the txtUsername ?


how to check whether the userid already exists or not?

Posted: Thu Jun 05, 2014 2:51 am
by B510

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

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