How can I get current user info in Custom Code?

Hello

I wanna do autocomplete for one of my fields by info from a current user (name, username etc…)

I have created relate field between User module and Contacts module so now I can see which user have which contact

Next I have one field named from Contacts
So I wanna autofill its value depends on which user creating the record

What I trying to do
Go to /custom/module/metadata/editview.php
Find from Contacts
add 'customCode' => ' ',

But what I should do next?

How can I get currentUser[contact] in editview ?

very similar functionality exists in the SuiteCRM right now.

If you look at the field created by then when you create a new record, it is automatically filled with the current user->username

I think I can do it via javascript but how I can access to current user info?

@Lyk37858

  1. You can create text field current_user_name_c and write the code into custom/module/metadata/editviewdefs.php (this correct file name):
'customCode'=>'<input value="{$fields.assigned_user_name.value}" id="current_user_name_c" name="current_user_name_c" readonly>'
  1. But the field created_by_name present in SuiteCRM by default for each module. Why don’t you want to use it?

thanks

  1. created_by = crurrentUser[username] but I wanna get another current user attribute. for example current user last name or Work Phone etc…

@Lyk37858

Make the file custom/modules/<module_name>/views/view.edit.php with the code

<?php
if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}
// change <module_name> to real module name 
class Custom<module_name>ViewEdit extends ViewEdit 
{
    public function display()
    {
        global $current_user;
        $this->bean->current_user_email_c=$current_user->email1; // example for primary email
        parent::display();
    }
}

Don’t modify the file editviewdefs.php . Add fields only.