Results 1 to 10 of 10

Thread: value from employees module to custom fields

  1. #1
    Kupido is offline Sugar Community Member
    Join Date
    Apr 2011
    Posts
    60

    Default value from employees module to custom fields

    Hello

    i need the phonenumber and emailadress from the employees module to the Contacts Modul in relation to the assigned to field.

    I created two text fields in studio for the Contacts Module.
    But now i don't know how i can retrieve the data to this two fields.

    I read some Threads and Blog, but in all threads are different ways

    must i go to the editview.php and change something in the array of this fields
    or must i go over logic_hooks?

    http://www.sugarcrm.com/forums/f3/co...-module-74994/

    here I don't understand where the code must insert.

    SugarCRM Developer Blog » Blog Archive » HOWTO: Using a relate field to populate a custom field

    and this i don't understand sorry

    and also tested this
    http://www.sugarcrm.com/forums/f3/fe...e-field-72983/

    But i found not the right way.

    Can any1 help me pls?

  2. #2
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is online now Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    404

    Default Re: value from employees module to custom fields

    Quote Originally Posted by Kupido View Post
    Hello

    i need the phonenumber and emailadress from the employees module to the Contacts Modul in relation to the assigned to field.

    I created two text fields in studio for the Contacts Module.
    But now i don't know how i can retrieve the data to this two fields.

    I read some Threads and Blog, but in all threads are different ways

    must i go to the editview.php and change something in the array of this fields
    or must i go over logic_hooks?

    http://www.sugarcrm.com/forums/f3/co...-module-74994/

    here I don't understand where the code must insert.

    SugarCRM Developer Blog » Blog Archive » HOWTO: Using a relate field to populate a custom field

    and this i don't understand sorry

    and also tested this
    http://www.sugarcrm.com/forums/f3/fe...e-field-72983/

    But i found not the right way.

    Can any1 help me pls?
    Hello Kupido
    Could you attach any image explaining that you want to do, please?
    Because I don't understand you well.
    Regards

  3. #3
    Kupido is offline Sugar Community Member
    Join Date
    Apr 2011
    Posts
    60

    Default Re: value from employees module to custom fields

    hello

    ok i make a screenshot



    Uploaded with ImageShack.us


    and this is in Contacts module

  4. #4
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is online now Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    404

    Default Re: value from employees module to custom fields

    Quote Originally Posted by Kupido View Post
    hello

    ok i make a screenshot



    Uploaded with ImageShack.us


    and this is in Contacts module
    Sorry Kupido, but I can't see the image well, it's small.
    Could you make it bigger?

  5. #5
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is online now Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    404

    Default Re: value from employees module to custom fields

    Hello again Kupido I have known see the image and now I understand you.
    You can do it through logic hook
    Steps:
    1. Hide these two fields (email and phone) in order to don't be displayed in edit view: editing editviewdefs.php of the module contacts
    2. Add these two fields to detailviewdefs.php of your module contacts in order to be displayed in detail view of contacts
    3. Like the other thread, create a logic hook in /custom/modules/contacts. With this logic hook you will get the value of the employee you have chosen in edit view, and you can make a query to the table employees of database in order to get the values of phone and email of the employee selected.


    Note: Your field called employee is of kind relate, and this kind of field is made up for two hidden fields: id_employee and employee. So with the logic hook you can get the value of this field by its id...the query to the database and the assignment of values will be something like:
    PHP Code:
    <?php
    require_once('/modules/Contacts/Contact.php');
    global 
    $db;
    class 
    employee_Hook{
             function 
    employee(&$bean$event$arguments){
                   
    $focus = new Contact();
                   
    $res $focus->db->query("SELECT phone,email FROM employees WHERE id ={$bean->id}");
                   
    $row=$focus->db->fetchByAssoc($res);
                   
    $bean->phone $row['phone'];
                   
    $bean->email $row['email'];
              }
    }
    ?>
    This code will be in the file named employee_Hook.php or the name you want to.
    In logic_hooks.php only will be:
    PHP Code:
    <?php
    $hook_version 
    1;
    $hook_array['before_save'][] = Array(1,"employee","custom/modules/Contacts/employee_Hook.php","employee_Hook","employee");
    ?>
    Good luck
    Last edited by garciasanchezdaniel; 2011-10-28 at 07:34 AM.

  6. #6
    Kupido is offline Sugar Community Member
    Join Date
    Apr 2011
    Posts
    60

    Default Re: value from employees module to custom fields

    ok thats nice

    ok i will test it tomorrow or this night
    and report my result.

    thanks a lot for the instruction.

    best regards

  7. #7
    Kupido is offline Sugar Community Member
    Join Date
    Apr 2011
    Posts
    60

    Default Re: value from employees module to custom fields

    Hello

    thanks a lot for the code.

    first employees where users.

    I look in my sql DB found the phone_work under the table users
    test the sql query SELECT phone_work FROM users WHERE id=' c7153ee6-b9aa-ac67-a9a0-4e80970a84a9'
    this works fine

    no i create a new php file: employee.php

    PHP Code:
    <?php
    require_once('modules/Contacts/Contact.php');
    global 
    $db;
    class 
    employee_Hook{
        function 
    employee(&$bean$event$arguments){
            
    $focus = new Contact();
            
    $res $focus->db->query("SELECT phone_work FROM users WHERE id = '{$bean->id}'");  //i don't understand from where get sugar the id? it means the id that is the same in sql table users. Here i get the phone number from the user?
            
    $row=$focus->db->fetchByAssoc($res);  
            
    $bean->assistant_phone $row['assistant_phone']; //assistent_phone is the fieldname in Contacts module
        
    }
        }

    ?>

    but also a problem is the emailadress, this is in another table email_adresses and the email adress is assigned to a email_id and the email_id is in table email_addr_bean_rel.. very complexe sql query.

    Can we not get the value from the users module direct?
    when i look under modules/users/editview.php and detailview.php i found the line's $sugar_smarty->assign('PHONE_WORK', $focus->phone_work);


  8. #8
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is online now Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    404

    Default Re: value from employees module to custom fields

    Hello Kupido I will answer your questions with my comments in the code in uppercase
    PHP Code:
    <?php
    require_once('modules/Contacts/Contact.php');
    global 
    $db;
    class 
    employee_Hook{
        function 
    employee(&$bean$event$arguments){
            
    $focus = new Contact();
            
    $res $focus->db->query("SELECT phone_work FROM users WHERE id = '{$bean->id}'");  //i don't understand from where get sugar the id? it means the id that is the same in sql table users. Here i get the phone number from the user?
           // $bean->id IS THE ID OF THE RELATE FIELD, SO, IN DATABASE, YOU HAVE TO GO TO CONTACTS_CSTM 
          //IN THIS TABLE THERE WILL BE TWO NEW FIELDS THAT MAKE UP THE RELATE FIELD
          //YOU CAN READ THIS THREAD TO UNDERSTAND WELL: http://www.sugarcrm.com/forums/f3/assign-value-related-field-73543/
            
    $row=$focus->db->fetchByAssoc($res);  
           
    $bean->assistant_phone $row['assistant_phone']; //assistent_phone is the fieldname in Contacts module THIS IS INCORRECT. YOU HAVE TO DO:
           
    $bean->assistant_phone $row['phone_work'];  // :) BECAUSE PHONE_WORK IS IN THE TABLE ''USERS'' OF DATABASE
        
    }
        }

    ?>
    I have to leave now, so put your results here and I will help you
    Cheers
    Last edited by garciasanchezdaniel; 2011-10-28 at 02:59 PM.

  9. #9
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is online now Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    404

    Default Re: value from employees module to custom fields

    Hello again Kupido, if you are having problems with this issue, you can attach here images with the table 'contacts' and the table 'users' in order to implement the logic hook adjusted to your needs. In this way, I will can see the fields we need.
    Realize that new fields are placed ultimately in the table. Regards

  10. #10
    Kupido is offline Sugar Community Member
    Join Date
    Apr 2011
    Posts
    60

    Default Re: value from employees module to custom fields

    Hello

    i had a think problem with the sql query
    I need the phone number from my user or better from the user who is assigend to contact.
    but the phone number from the user is in the sql table users.
    and the field id (assigned_to) is stored in the table contacts_cstm

    So i need a other sql query? or have i a mistake in my thinking?


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 2011-03-29, 10:40 AM
  2. Replies: 6
    Last Post: 2010-10-15, 04:37 PM
  3. Solution to allowing custom fields in Employees
    By SugarDev.net in forum Developer Help
    Replies: 38
    Last Post: 2010-08-13, 07:05 PM
  4. Add Export fields in Employees Module
    By akron in forum Help
    Replies: 5
    Last Post: 2010-05-08, 07:10 PM
  5. Empty Custom Fields in Employees
    By nortius in forum Help
    Replies: 1
    Last Post: 2006-09-29, 09:01 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •