sc_redir macro - simple questions, seems bug?

hi pals

i got simple form (single record), many records in it, and mysql db

on insert or on update (when one field is equal to 1 for example) i want to to display a control application

sc_redir(targeted_control_app);

problem is if i put it OnAfterUpdate it does redirect ok, but the record is not saved actually in the database, seems like redirecting (even if conditional like field=1 or x that is fine) but database does NOT gets the new updated values!

code is simple as this

sc_redir(targeted_control_app);

i tried OnAfterUpdate and also tried OnAfterInsert

am i missing something here? i know it was working before, OnAfterUpdate was updating the record and then redirecting the user to the other application

now, if i remove that code, it does update the db with that small stupid message “Data Modified” without issues, but the form doesn’t redirect to the other app as i want to do

any idea?

One more thing please, can i add confirmation message so before user clicks “update record” something like “this will update and redirect you to previous screen, are you sure?” yes no…

I was reading in macros and found out that this confirmation thing

sc_confirm (“Do you really wish to execute this action??”);

but it is written that works onClick, didn’t know how or where or with which event i should use it

You need to commit the transaction before the redirect
Lookup macro
Sc_committ

Kevin

thanks for your reply Kevin

do you mean sc_commit_trans(); ?
and what is the lookup you said for?

He means sc_commit_trans. With lookup he meant that you needed to lookup the macro for yourself :stuck_out_tongue_winking_eye:

In general the transaction is ended as the last step. If you escape your application then you don’t hit the commit. That’s why you need to apply that yourself.

thanks albert, you are both correct, with sc_commit_trans(); it works and updated the db.

i still want to know how to make a confirmation message so if clicked ok to go ahead, otherwise cancel and stay in the same place, i tried the sc_confirm thing but don’t know they mean by onClick event! it is not in the events list.

re sc_confirm - NOTE (as per manual): Valid only in the PHP programming code that runs when called through a toolbar button.

To have a “delete” confirmation pop-up go to:

Application | Messages

Then put a message in the “Message to confirm Delete” box, e.g. This will delete this record. Are you sure?

… and that’s it. It pops up an OK/Cancel dialog.

[QUOTE=adz1111;32040]re sc_confirm - NOTE (as per manual): Valid only in the PHP programming code that runs when called through a toolbar button.

To have a “delete” confirmation pop-up go to:

Application | Messages

Then put a message in the “Message to confirm Delete” box, e.g. This will delete this record. Are you sure?

… and that’s it. It pops up an OK/Cancel dialog.[/QUOTE]

hi adz, thanks dear, I’m aware about the message confirmation that is in Application-> messages, but this will bring back the previous screen before the insert/update, hence the redir macro will not work!? what you think? did you try the redir macro in combination with application-> messages confirmation and it worked? where did you put the redir macro in which event?

Hello:

Question?, what does the control application does?. just to have a better understanding of your problem.

Regards

hi kafecadm,
just to give overview message about what was done in the form and let the end user choose where to go next, something like, your record was added, click here to go here, click here to go there, if you want to do that, click here… better than sending the user to a form or page that is pointless for him!?

@MikeDE
Right - didn’t read too much into the sc_redir() bit (blush).

The thing with sc_redir() is that it’s a one way deal. It’s not like calling a function where execution goes to the called function and afterwards returns to the caller. When you use sc_redir, control shifts totally to whatever app you sent it - and that’s it (hence the need to commit_trans() before you use the redir if DB updates occurred).

So, any events you rely on AFTER calling redir never get executed. The only way around that is too keep track manually (as far as I know). One way is through global vars. You can create one - say [status] and when you do an insert / update / delete etc. Before you call the sc_redir, set [status] to “insert”, “update”, “delete” etc. In the target app you can check [status], reset it to “”, and then show a pop up or whatever you want.

Or (more likely for your case) after updating [status], redir (after a commit) to a control app - show your control app “pop up” - capture the OK or Cancel - and then redir back to the original app. In the original app check [status], reset it, and then do an actual insert or whatever

@kafecadm
The control app is designed to help for control type applications. That is, nothing directly to do with a backend DB. It does not need a table / query etc associated with it. The login app is a prime example of a control app.

thank you adz bro, too much info to analyze and seems hard to apply but overall your logic is valid indeed :slight_smile:

i was thinking, why not to use onvalidate event? i mean if you put the redir macro in after update, assume we are done the update and this will redirect to new app, but onvalidate will alert the user somehow before updating the record, so again we need a simple code to act like confirmation message in OnValidate events and if user choose ok, then goes to update > on after update > then apply commit > redirect to new app… done. still curious to know what our guys would do in such case, we have many experts here and i’m sure some of us use this regularly at least when you have critical values will change in the form and we need to make confirmation to end user… but maybe nobody is interested to send the user to specific app afterwards… debatable :smiley:

cheers