Save from code?

I have a form, and do some code when I call a PHP button on toolbar.

In this method, I do some task, and have to redirect to the new document created, all is ok, but before redir, I need to put a value on a field and save.

What is the way to go?

P.S.: Basically is a Quote->Bill generate. When you are on a quote, you can generate a bill, but before redir to the bill created, I need to put the new id to {billAssigned} and then redir.

{facturado} = $idDocumentoGenerado;
sc_redir("form_documentocomercial", id=$idDocumentoGenerado; generarReferencia=true);

Obviously, this works like a charm, but without saving {facturado} field.

You did a commit before the redirect right??
Kevin

I think what you want is here:

http://www.scriptcase.net/forum/showthread.php?8125-how-to-print-the-record-id-on-control-application-directlyAFterInsert!&p=32574&viewfull=1#post32574

Dave

I thought about this, but I’m not on an event, I did from a button in toolbar. I did an UPDATE query.

hi Giu, why use sc_redir in a button, try sc_link instead?

not sure but try
sc_commit_trans() ;

before redir

Hi all,

I would like to retake this. Some ideas?

Must it happen before the redirect? If not, is this an option: have a global [QuoteID] and run an UPDATE query linking this to {BillID} (in either the quote or bill tables) in onAfterInsert in the Bill form app. This way if user cancels, there is no empty Bill record linked to the quote.

it’s a button in toolbar. Before I do some tasks, I want to make sure data in form si saved

It’s not clear to me why you cannot achieve this with the save button and redirect within your onValidateSuccess.

Giu, we know you are an SC guru so if you share the details, some of us can learn from your use case and not insult you with simplistic suggestions. :slight_smile:

Because it’s a process I want to do just if user click on a button, not always when you save.

Giu, we know you are an SC guru so if you share the details, some of us can learn from your use case and not insult you with simplistic suggestions. :slight_smile:

I’m not a guru. All here have a lot to learn from each other. As we say here, with a poor translation… There aren’t stupid questions, but smart answers

I recapitulate.
There are some tasks I need to do just when the user press a button. When this button is pressed, I want to save the form first, to make sure, if user did some changes and didn’t saved, are saved before the tasks starts.

Create PHP Method i.e. save_and_redir():

do all your tasks here …
echo “<script>nm_atualiza(‘alterar’);</script>”;
sc_commit_trans();
sc_redir(…);

Don’t do the tasks in the button, especially when there are form fields involved.
You might not be able to access those fields.

Create a button:

save_and_redir();
sc_exit(sel);

That should do it.

jsb

[QUOTE=jsbinca;36500]Create PHP Method i.e. save_and_redir():

do all your tasks here …
echo “<script>nm_atualiza(‘alterar’);</script>”;
sc_commit_trans();
sc_redir(…);

Don’t do the tasks in the button, especially when there are form fields involved.
You might not be able to access those fields.

Create a button:

save_and_redir();
sc_exit(sel);

That should do it.

jsb[/QUOTE]

Giu: pls confirm this worked.

I have it in my TODO. Didn’t got the time to test it, but I will update

I don’t think jsb gives something doesn’t work