Custom function to set default value?

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
bmason
Posts: 9
Joined: Aug 29, 2019 2:56 pm

Custom function to set default value?

Post by bmason »

Is there a way to write a custom function that would set the default value for a custom field? I have written such a function and placed it in custom_functions_inc.php but it does not appear to be running. What would I have to name the function, and how would I invoke it in the Default Value field of the custom field?

Thanks in advance for your help!

bmason
Posts: 9
Joined: Aug 29, 2019 2:56 pm

Re: Custom function to set default value?

Post by bmason »

Let me explain further what I am trying to do. I have created a custom enumeration field named Verified By, and I am using the following custom function to populate it:
function custom_function_override_enum_users()
{
$t_users = project_get_all_user_rows( helper_get_current_project(), ANYBODY );
$t_enum = array();
foreach ( $t_users as $t_user ) {
$t_enum[] = $t_user['username'];
}
sort( $t_enum );
$t_possible_values = "|";
$t_possible_values = $t_possible_values . implode( '|', $t_enum );
return $t_possible_values;
}
In the Possible Values for the Verified By field, I specify =users. This is working great - it lists all the users in the drop-down list.

I created another custom function as follows:
function custom_function_override_enum_thisuser()
{
$the_userid = auth_get_current_user_id();
$the_username = user_get_username( $the_userid );
return $the_username;
}
When I put =thisuser in Default Value for the Verified By field, it does not appear to do anything. However, if I put =thisuser in Possible Values, the currently-logged-in-user is the only user in the list. (Thus I know I have constructed the custom_function_override_enum_thisuser function correctly.)

Any advice would be appreciated.

Post Reply