error at onBeforeInsert

SOLVED Thanks Giuseppe

please help

i had wrote some script onBeforeInsert in form application, but every i run form app to add my script doesnt work

but while i put my script at onLoad that work

but i couldnt put that change at onLoad because this is uniqueID

thanks in advance

Jaisyullah

my script :

sc_field_readonly({address_domisili}, ‘on’);
sc_field_readonly({city_domisili}, ‘on’);
sc_field_readonly({kecamatan_domisili}, ‘on’);
sc_field_readonly({kelurahan_domisili}, ‘on’);

/**

  • Selecting a field from another table
    */

// Check for record
$check_sql = “SELECT max(custCode)”
. " FROM tbcustomer";
sc_lookup(rs, $check_sql);
$id = {rs[0][0]}+‘1’;

if ($id < ‘10’){
{custCode} = “00000$id”;
}
elseif ($id < ‘100’){
{custCode} = “0000$id”;
}
elseif ($id < ‘1000’){
{custCode} = “000$id”;
}
elseif ($id < ‘10000’){
{custCode} = “00$id”;
}
elseif ($id < ‘100000’){
{custCode} = “0$id”;
}
elseif ($id < ‘1000000’){
{custCode} = “$id”;
}

Solution : on custCode’s field i just need to untick ‘required’ option in edit field menu

[B]thanks Giuseppe, you are rocking man

;)[/B]

Try:
In Onload Event you must set this: “The macro sc_field_readonly does not work in Onbeforeinsert”:

sc_field_readonly({address_domisili}, ‘on’);
sc_field_readonly({city_domisili}, ‘on’);
sc_field_readonly({kecamatan_domisili}, ‘on’);
sc_field_readonly({kelurahan_domisili}, ‘on’);

On BeforeInsert:

// Check for record
$check_sql = “SELECT max(custCode)”
. " FROM tbcustomer";
sc_lookup(rs, $check_sql);
$id = {rs[0][0]}+‘1’;

if ($id < ‘10’){
{custCode} = “00000$id”;
}
elseif ($id < ‘100’){
{custCode} = “0000$id”;
}
elseif ($id < ‘1000’){
{custCode} = “000$id”;
}
elseif ($id < ‘10000’){
{custCode} = “00$id”;
}
elseif ($id < ‘100000’){
{custCode} = “0$id”;
}
elseif ($id < ‘1000000’){
{custCode} = “$id”;
}

Your select can set like: (This generate the mask for your custCode)
select lpad(max(custCode) +1, 6, “000000”) FROM tbcustomer;

thanks in advance, ill try this now

dear alvagar,

i couldnt make any changes with onBeforeInsert script on form application

even my running id and your suggestion above

please help

Regards

Can you post a screenshot of your custCode SC field definition?

Dear Giu

Screenshot Attached

if i write script in onLoad event this work perfectly

but i need script work only while add new records

thanks in advanced

Screenshot (3).png

Screenshot (1).png

Screenshot (5).png

Screenshot (4).png

First, if your screenshots has sensible data, please, remove it, and/or ofuscate next time you upload. I don’t think somebody would like to see her name posted on a forum.
Said that, put var_dump($id); after your line 4, and post screenshot.
Attach another screenshot of fields configuration when you press “Edit Fields” option.

[ATTACH=CONFIG]n80456[/ATTACH]

2017-10-26 13_22_21.png

Okay thank you, im so sorry right that you have said… its sensible data

i had trying your suggest, still nothing any show result

screenshot attached

Thanks

Screenshot (6).png

Screenshot (7).png

Screenshot (8).png

var_dump should output the value of $id

Hi Giu

There is nohing sir

Regards
Jaisyullah

Close as solved