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.
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.
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.
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.
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.
Usually there is a flag, request parameter, or form state that indicates whether the form is creating a new record or editing an existing one. The exact variable depends on the framework or application you’re working with.
A common approach is to check whether an existing record ID is present. For example, if the form has something like id, record_id, or edit_id, an empty value often means you’re creating a new record, while a populated value means you’re editing an existing record.
If you can share the relevant form/controller code (especially the part that loads the form and handles the submit), it should be possible to identify exactly where that state is being set. The Spanish variable names aren’t necessarily a problem once we see how they’re being used.