Page 1 of 12
Is it possible to have the same button run both a create service and an update service?
Posted: Tue Nov 25, 2014 4:34 am
by Ellen Schlechter
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??
Is it possible to have the same button run both a create service and an update service?
Posted: Tue Nov 25, 2014 5:21 am
by Yurii Orishchuk
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.
Is it possible to have the same button run both a create service and an update service?
Posted: Tue Nov 25, 2014 1:38 pm
by Ellen Schlechter
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.
Is it possible to have the same button run both a create service and an update service?
Posted: Tue Nov 25, 2014 2:40 pm
by Alena Prykhodko
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 the same button run both a create service and an update service?
Posted: Sat Nov 29, 2014 3:35 pm
by Ellen Schlechter
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?
Is it possible to have the same button run both a create service and an update service?
Posted: Sat Nov 29, 2014 9:00 pm
by Egor Kotov6832188
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.
Is it possible to have the same button run both a create service and an update service?
Posted: Sat Nov 29, 2014 9:52 pm
by Ellen Schlechter
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??
Is it possible to have the same button run both a create service and an update service?
Posted: Sun Nov 30, 2014 10:12 pm
by Yurii Orishchuk
Hi Ellen,
You missed JS code for "where" request parameter in query service.
Please read here:
https://getsatisfaction.com/apperyio/...
Regards.
Is it possible to have the same button run both a create service and an update service?
Posted: Mon Dec 01, 2014 3:15 am
by Ellen Schlechter
{"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();
};
Is it possible to have the same button run both a create service and an update service?
Posted: Mon Dec 01, 2014 5:40 am
by Yurii Orishchuk
Ellen,
Nope,
You should use "_id".
Regards.