Prefix Value Into Field

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
tandrew
Posts: 12
Joined: 2018-09-26 12:46

Prefix Value Into Field

Post by tandrew » 2018-10-05 01:09

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.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Prefix Value Into Field

Post by pbottcher » 2018-10-05 09:40

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?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

tandrew
Posts: 12
Joined: 2018-09-26 12:46

Re: Prefix Value Into Field

Post by tandrew » 2018-10-05 13:02

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.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Prefix Value Into Field

Post by pbottcher » 2018-10-05 14:32

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']);
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

tandrew
Posts: 12
Joined: 2018-09-26 12:46

Re: Prefix Value Into Field

Post by tandrew » 2018-10-08 12:56

Hi,

This also can. But have not tried out yet.

Will keep posted.

Regards,

Post Reply