Page 1 of 1

Concatenation with date() to get month

Posted: 2021-05-05 04:28
by devedix
Hi all,
I try to make an autofill field in the before insert function in the hooks/table-name.php

Code: Select all

$data['prefix'] = 'DO/Company/'.date('m');
But it only returns 'DO/Company/' without the month
Is there something wrong with my code?

Thanks

Re: Concatenation with date() to get month

Posted: 2021-05-05 04:38
by jsetzer
Does $data contain a prefix-value?

prefix field must not be readonly.

For narrowing down I would debug the contents of $data in before_insert hook to see if there is any $data['prefix'] array item at all:

Code: Select all

var_dump($data);
exit();
:oops: SORRY, I was too fast. My answer is not helpful as you said, your function DOES return something. But I cannot delete this post. Please ignore it.

Re: Concatenation with date() to get month

Posted: 2021-05-05 05:16
by devedix
Hi @jsetzer,
Thanks for the fast response.
Yes, it does return the string but without the month.
By the way, I really like the AppginiHelper Javascript library.
Nice work.

Re: Concatenation with date() to get month

Posted: 2021-05-05 05:52
by pbottcher
Hi,

I'm not sure, but I think you cannot use the hooks to manipultate autofill fields as they are picked up from the first field that points to your lookup record. If you want to do that, you will need to change the field to a read-only field and the approriate type and calc your value manually.

Re: Concatenation with date() to get month

Posted: 2021-05-05 06:55
by devedix
Hi @pböttcher,
Thanks for the answer, I will try your suggestion.

Re: Concatenation with date() to get month

Posted: 2021-05-05 07:32
by devedix
Hi all,
Just want to update you, I've found out the problem.
:oops: This is really embarrassing, a silly beginner mistake.
The reason why the month did not show up because of the max-length of the field.
After I increase the max-length of the field, the code works just fine.
Thanks again for all your support.