I want to have a button that upon the first time you ever click it, it uses the create service to create something for the database but every other time you click it from there on out, it updates it.
Any thoughts??
I want to have a button that upon the first time you ever click it, it uses the create service to create something for the database but every other time you click it from there on out, it updates it.
Any thoughts??
Hi Ellen,
Yes,
You can add "click" event handler with action "Run javascript" with code:
pre
//You should replace this "true" with your right condition(in accordance to your logic).
var condition = true;
if(condition){
//Run create service.
createServiceDataSource.execute();
}
else{
//Run udpate service.
updateServiceDataSource.execute();
};
/pre
Regards.
I apologize for my ignorance, but could you please explain what "true" means and what other options there are? I don't really know code so I'm not sure what is supposed to be there.
Dear Ellen,
Basic and above coding knowledge are required. Please read more about javascript(ECMAScript) language types and language in general first, you can find more information online.
Writing of custom code is outside the scope of our support.
Also you may be interested in services we provides , please read more here http://appery.io/services
Is it possible to have it search the database to see a user has already created something, then update it if they have? Instead of the other way?
Yes, you can call service that will search it, on event success for that event you can check if response is not empty, then call second service.
Here's what I did. For some reason it is not working so could you please tell me if I missed a step somewhere?
I mapped it _id to a label displayed on the panel as a form of identification
Made a query service with the label mapped to the where parameter
Upon its success, I ran the update service.
Upon "Save" button click it runs the search service.
I don't have any JS incorporated in it this at this point because I didn't think I would need it. Its not creating anything in the database so how do I get it to do it only once??
Hi Ellen,
You missed JS code for "where" request parameter in query service.
Please read here:
https://getsatisfaction.com/apperyio/...
Regards.
{"userid": "hereIsYourUserIdYouWantToTest"}
So does it seem right that I would put where you have "hereisyouruser..." i put "username" because that is the name of the column in the database that I want to be searched??
Then do I use a code like this? Would I run this JS upon button click?
var username = data.length 0;
if(username){
check_update.execute();
}
else{
checkbox_create.execute();
};
Ellen,
Nope,
You should use "_id".
Regards.