Page 1 of 1

Prefix Value Into Field

Posted: 2018-10-05 01:09
by tandrew
Hi,

Need help on how to prefix value into the field before data entry.

field = leave_number

need fill with prefix before data entry for example below:-

leave number: ABC00000001

tried using tablename-tv.js hook but fail to do so.

thanks in advance.

Re: Prefix Value Into Field

Posted: 2018-10-05 09:40
by pbottcher
Hi,
can you please explain what you try to acheive? Thhe tablenamne-tv.js will apply changes to the tableview. So you only want to see a prefix in the table view where as the real data has no prefix?

Re: Prefix Value Into Field

Posted: 2018-10-05 13:02
by tandrew
Hi,

trying to achieve pre-fill field with prefix + auto increment number

(field) = leave_number

When user click insert new, need to populate leave_number with prefix + auto increment number

As example = ABC000001

try achieve sql query success but manage to do it with number increment only.
not sure how to prefix ABC in front of it.

Thanks.

Re: Prefix Value Into Field

Posted: 2018-10-05 14:32
by pbottcher
Hi,

not sure if this is what you are looking for, but you could use either the primary key (if you have one that is autoincremented) and use the after_insert, after_update (if needed) hook functions to apply your prefix

or you can add an additional field that will hold your unique number (as you described above and you use the after_insert, after_update (if needed) hook functions to apply your prefix to the autoincremented number.


something like
sqlvalue("UPDATE ##tablename## set leave_number=concat("ABC",lpad(ID, 6, 0) where id =".$data['selectedID']);

or

sqlvalue("UPDATE ##tablename## set leave_number=concat("ABC",lpad(leave_number_autoinc, 6, 0) where id =".$data['selectedID']);

Re: Prefix Value Into Field

Posted: 2018-10-08 12:56
by tandrew
Hi,

This also can. But have not tried out yet.

Will keep posted.

Regards,