Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

Is it possible to have the same button run both a create service and an update service?

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??

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

Is it possible to have the same button run both a create service and an update service?

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.

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

Is it possible to have the same button run both a create service and an update service?

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.

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

Is it possible to have the same button run both a create service and an update service?

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

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

Is it possible to have the same button run both a create service and an update service?

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?

Egor Kotov6832188
Posts: 0
Joined: Wed Nov 19, 2014 5:15 pm

Is it possible to have the same button run both a create service and an update service?

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.

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

Is it possible to have the same button run both a create service and an update 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?

  1. I mapped it _id to a label displayed on the panel as a form of identification

  2. Made a query service with the label mapped to the where parameter Image

  3. Upon its success, I ran the update service.

  4. 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?? Image

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

Is it possible to have the same button run both a create service and an update service?

Hi Ellen,

You missed JS code for "where" request parameter in query service.

Please read here:

https://getsatisfaction.com/apperyio/...

Regards.

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

Is it possible to have the same button run both a create service and an update service?

{"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();
};

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

Is it possible to have the same button run both a create service and an update service?

Ellen,

Nope,

You should use "_id".

Regards.

Return to “Issues”