How to determine if form is in insert or edit mode?

Hi,

I need to do some conditional coding based on if a form is adding a new record or editing an existing record.

There must be a variable somewhere that sets this, but the source code is somewhat confusing, and a lot of it is in Spanish, so it is hard to guess which one it might be.

Thanks

Tony

All is in the manual bro…

Buttons
sc_btn_copy
This macro returns “true” when the “copy” button is selected in a form.
sc_btn_delete
This macro returns “true” when the “Delete” button is selected in a form.
sc_btn_display (“Button_Name”,“on/off”)
This macro activate toolbars buttons on the application in execution time.
sc_btn_insert
This macro returns “true” when the “Add” button is selected in a form.
sc_btn_new
This macro returns “true” when the “Add New” button is selected in a form.
sc_btn_update
This macro returns “true” when the “Save” button is selected in a form.

regards

Thanks,

It seems like a button property did not belong to what I was looking for and so it escaped me. However, as you said, it worked, especially after I sorted the logic out.

Tony

Glad to hear

Regards

So does “selected” mean that the button exist on the form and not that it’s been selected/pressed?

That is one of the reasons why it confused me at the start. But I used an if (sc_btn_new) statement to check to see if it did anything when in edit mode, and it bypassed the code in there, so it worked.

No it means it returns true when you’ve click on it

About this question , it is possible to know in any event as like OnValidate the current mode of the form ? if a user is inserting or editing ?

Example in onvalidate event, i need compare it.
if (CURRENT_MODE = ‘INSERT’) then …
elseif (CURRENT_MODE = ‘EDIT’) then …

Yes, with macros mentioned in this thread

NOT WORK

if (CURRENT_MODE == 'INSERT') echo 'INSERT<br>';
elseif (CURRENT_MODE == 'EDIT') echo 'EDIT<br>';
else echo '?????<br>';

output:
???

error:
Use of undefined constant CURRENT_MODE - assumed ‘CURRENT_MODE’
Use of undefined constant CURRENT_MODE - assumed ‘CURRENT_MODE’

THIS WORK

echo "nmgp_opcao = $this->nmgp_opcao<br>";

// edit
nmgp_opcao = igual
nmgp_opcao = inicio

// new
nmgp_opcao = novo

// insert
nmgp_opcao = incluir

// update
nmgp_opcao = alterar

// delete
nmgp_opcao = excluir

// error - nothing
nmgp_opcao = nada

I never used CURRENT_MODE, didn’t noticed about this constant, and is getting you an error because this constant don’t exists. Maybe comes from old SC versions.

For events like onvalidate I use sc_btn_new/delete and so on macros. For load, I just ask if PK has value. (if ({id}>0 …)

In This Tread i was asking about same question.
Does is possible to know in any event as like OnValidate the current mode of the form ? if a user is inserting or editing ?

It would be nice if the SC staff can solve this question.:confused:

read my post

you can check by sc_btn_new onLoad Event

if (sc_btn_new)
{
echo “Record in insert Mode”;
}else
{

echo "Record in update Mode";
}

I know that it’s an old post by personally I simple test the ID value of the record

If the ID < 1 then you are in insert mode else you are in update mode.