Sc_error_exit() and sc_btn_new

In the onLoad event of a form if we present this process:
if(sc_btn_new)
{
process 1;
}else{
process 2;
}
When the user has entered their data, pressing the insert button, and in the onValidate or onValidateFailure event occurs:

…sc_message_error(‘Error’); sc_error_exit();

The form returns to the onLoad event, but sc_btn_new is no longer true, since it may have changed its value from true to false by pressing the insert button. In this case, process 2 is executed, which should not be the case, since we are still in the process of inserting a new record, the only thing that has happened is that we do not allow it to be inserted as it is because some data is wrong.

The user is only being informed to correct his input data and try to add the record again, so the form should remain in the state left by process 1, not execute process 2, which will possibly leave the form in other state, for example read-only or not visible fields, disappearing blocks, etc., for an update process, not for a new record.

If the true value of sc_btn_new cannot be preserved, for whatever reason, within the Scriptcase system when the insert button is pressed, Scriptcase could create a new macro called for example sc_validate_error and be able to act like this:
if(sc_btn_new)
{
process 1;
}else{
if(!sc_validate_error)
{
process 2;
}
}
Greetings

1 Like

That error was reported some time ago, BUT SC Team does not fix it.
I Hope that error be fixed soon.

1 Like

As well as many others bugs we report constantly.

Instead of fixing bugs they prefer to add new useless features until they will loose all their customers.

For new project I have decided to drop SC because support is poor.

Well, I have it resolved with a global output variable that is activated or deactivated in onValidate and wonders in onLoad, I was only trying to scriptcase see this circumstance.
onValidate:
if (Test == error)
{
[g_error] = true;
sc_error_message(‘error’);
sc_error_exit();
} else {
[g_error] = false;
}
onLoad:
if (sc_btn_new)
{
Process 1;
} else {
If (! [g_error])
{
Process 2;
}
Greetings and thanks for your comments

I think you must to validate other possibility like when the user click update, insert or delete button:
Since SC execute same event Onvalidate!!

if ((sc_btn_delete) || (sc_btn_update) || (sc_btn_insert))

Alvagar, I put an example of my code in a simple form.
As you can see (I’m telling you this in passing so you don’t get surprised when reviewing the code), I don’t let SC act directly on Required fields either! The form has fields that can be set to ‘not visible’. Depending on the selection made from a primary field {codtipo}, they appear or disappear depending on the selection, and even if they are hidden, when marking them as Required in Edit Fields, SC would treat them as Required, ALL, visible and invisible, and would always give an error of Required Field with those that are hidden, when they are not really required because they do not belong to the {codtipo} that the user has selected, do you understand? In short, it is complex, another problem that SC does not take into account, if the field has been hidden, how will it be Required? The user cannot enter information in it, then? What matters to us is the way in which the form returns to the onLoad after pressing Insert, Update or Delete.

onValidate code:

if(!{sc_btn_delete})
{
if(empty({codtipo}) ||
(empty({numserie_pro}) && {codtipo} <> 5) ||
(empty({numserie_rec}) && {codtipo} > 5) ||
empty({codformapago}) ||
empty({codcuenta}))
{
[g_error] = 1;
sc_error_message(‘Los campos con * son obligatorios.’);
sc_error_exit();
}
}
[g_error] = 0;

Of course, it is checked if the operation carried out by the user is not a Delete, if it were, there is no need to check the variable [g_error] in the onLoad event, but if it were Update or Insert if it is necessary to know if it returns to onLoad from an ERROR or NO.
In this way, if it is in the NO ERROR state, we will be able to carry out procedures that we would not do if the form is incomplete and is not yet ready to be updated or entered in the DB, these procedures may include reforming the appearance of the form, fields, blocks , etc… If there has been an ERROR in the form, transforming tasks or calculations cannot be performed, the form must be left as initially entered in sc_btn_new until there are no errors in it.
Don’t you think?
Greetings