Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Retrieve all contacts(beans) of the Contacts Modul

  1. #1
    lrgervais Guest

    Default Retrieve all contacts(beans) of the Contacts Modul

    Hello to every one,

    i would like to know, if it is possible to retrieve all beans of the Contacts Modul. And how can i achieve that?

    regards,
    Stev

  2. #2
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: Retrieve all contacts(beans) of the Contacts Modul

    hi
    PHP Code:
    $contacts = new Contact(); 
    $result $contacts->get_full_list(); 

  3. #3
    lrgervais Guest

    Default Re: Retrieve all contacts(beans) of the Contacts Modul

    Hi Kir,

    Thank you for your reply. i have the following code, but i get an error on the browser.
    require_once("modules/Contacts/Contact.php")

    class changeContact(){

    function change(){
    $contacts = new Contact();
    $result = $contacts->get_full_list();
    }

    }

    am i doing somethin wrong?
    regards,
    Stev

  4. #4
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: Retrieve all contacts(beans) of the Contacts Modul

    Quote Originally Posted by lrgervais View Post
    Hi Kir,

    Thank you for your reply. i have the following code, but i get an error on the browser.
    require_once("modules/Contacts/Contact.php")

    class changeContact(){

    function change(){
    $contacts = new Contact();
    $result = $contacts->get_full_list();
    }

    }

    am i doing somethin wrong?
    regards,
    Stev
    What is the text of error?
    Where do you fire this function? What is the purpose?
    btw try to not use such name as chacnge(). Better to be sure that name is unique.

  5. #5
    lrgervais Guest

    Default Re: Retrieve all contacts(beans) of the Contacts Modul

    The recieve a message like the server is unreachable.
    i have a logic hook with after save event, and after a Contact is save the function is called. I want to update the default Mail address of all Contacts, i have a custom field Work-email and i want to put the value of this field to the default email address and this for all contacts.

    regards,
    Stev

  6. #6
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: Retrieve all contacts(beans) of the Contacts Modul

    i don't think that above code is related to error but what you do with email addresses.
    Do you know how exactly is email addresses is stored in SugarCRM?
    I mean that they are stored in separate table and handle them is not so simple like other fields in modules.

    anyway you can paste here a code of your logic hook here (but use [ PHP ] tags, please ). will see

  7. #7
    lrgervais Guest

    Default Re: Retrieve all contacts(beans) of the Contacts Modul

    Hi Kri,

    here ist my logic_hooks.php file:
    <?php
    // Do not store anything in this file that is not part of the array or the hook version. This file will
    // be automatically rebuilt in the future.
    $hook_version = 1;
    $hook_array = Array();
    // position, file, function
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1, 'Contacts push feed', 'modules/Contacts/SugarFeeds/ContactFeed.php','ContactFeed', 'pushFeed');

    $hook_array['after_save'] = Array();
    $hook_array['after_save'][] = Array(1, 'Default Mail', 'custom/modules/Contacts/ChangeEmail.php','ChangeEmail', 'change');

    $hook_array['process_record'] = Array();
    $hook_array['process_record'][] = Array(1,'Mass Update', 'custom/modules/Contacts/MassUpdate.php', 'MassUpdate', 'update');

    $hook_array['after_ui_frame'] = Array();

    ?>

    here my MassUpdate.php file

    <?php
    //$GLOBALS['log']->debug("HEREIAM:".print_r($focus,true));
    //prevents directly accessing this file from a web browser
    require_once('modules/Contacts/Contact.php');
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    class MassUpdate {

    function update(&$bean, $event, $arguments){
    $contacts = new Contact();
    $results = $contacts->get_full_list();

    foreach ($results as $contact) {
    echo $contact->last_name;
    }
    }
    }
    ?>

    but when i get on the listView of the module Contacts, none of the contacts appears(see Pic). Like you can see the bottom of the pic is empty.

    Name:  Bildschirmfoto 2013-04-23 um 09.18.16.png
Views: 329
Size:  41.3 KB

  8. #8
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: Retrieve all contacts(beans) of the Contacts Modul

    I can't understand what do you want to achieve by your massupdate function.
    Proccess record hook fire code to every record in the listview on-the-fly by default.
    And you get list of all contacts to every contact...

    I could help you via skype : kirillbelousov

  9. #9
    lrgervais Guest

    Default Re: Retrieve all contacts(beans) of the Contacts Modul

    Hi,

    the change function has to look this way(with process record look)
    function update(&$bean, $event, $arguments){
    $sea = new SugarEmailAddress;
    $primary = $sea->getPrimaryAddress($bean);
    if($primary != $bean->work_email_c){
    $emailaddress = $bean->work_email_c;

    $bean->load_relationship("email_addresses");
    $emails = $bean->get_linked_beans("email_addresses", "EmailAddress"); //Retrieve all the emails of Contacts

    foreach ($emails as $mail) {
    $bean->emailAddress->addAddress($mail->email_address, false, null, false); // set all email addresses as not email primary addresses
    }

    $bean->emailAddress->addAddress($bean->work_email_c, true, null, false); // add new email and set it as primary address
    $bean->emailAddress->save($bean->id, $bean->module_dir);
    }
    }


    but just for test purposes i wrote this one(a empty function update()), and the listView of Contacts is also empty. i dont understand what i'm doing wrong.
    the problem here is obviously not my function.
    <?php
    //$GLOBALS['log']->debug("HEREIAM:".print_r($focus,true));
    //prevents directly accessing this file from a web browser
    //require_once('modules/Contacts/Contact.php');
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    class MassUpdate {

    function update(&$bean, $event, $arguments){

    }
    }
    ?>

  10. #10
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: Retrieve all contacts(beans) of the Contacts Modul

    Quote Originally Posted by lrgervais View Post
    Hi,

    the change function has to look this way(with process record look)
    function update(&$bean, $event, $arguments){
    $sea = new SugarEmailAddress;
    $primary = $sea->getPrimaryAddress($bean);
    if($primary != $bean->work_email_c){
    $emailaddress = $bean->work_email_c;

    $bean->load_relationship("email_addresses");
    $emails = $bean->get_linked_beans("email_addresses", "EmailAddress"); //Retrieve all the emails of Contacts

    foreach ($emails as $mail) {
    $bean->emailAddress->addAddress($mail->email_address, false, null, false); // set all email addresses as not email primary addresses
    }

    $bean->emailAddress->addAddress($bean->work_email_c, true, null, false); // add new email and set it as primary address
    $bean->emailAddress->save($bean->id, $bean->module_dir);
    }
    }


    but just for test purposes i wrote this one(a empty function update()), and the listView of Contacts is also empty. i dont understand what i'm doing wrong.
    the problem here is obviously not my function.
    <?php
    //$GLOBALS['log']->debug("HEREIAM:".print_r($focus,true));
    //prevents directly accessing this file from a web browser
    //require_once('modules/Contacts/Contact.php');
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    class MassUpdate {

    function update(&$bean, $event, $arguments){

    }
    }
    ?>
    May be the naming is the problem?
    MassUpdate it is internal sugarcrm class already declared here: sugarroot/include/MassUpdate.php
    try to change class name to something unique.
    Tell the result

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Retrieve linked beans of a Contact through C# SOAP
    By tobydz in forum Developer Help
    Replies: 1
    Last Post: 2012-12-04, 11:15 PM
  2. How to retrieve Primary Email from Contacts using SOAP
    By FireCRM in forum Developer Help
    Replies: 4
    Last Post: 2009-02-02, 06:51 PM
  3. Replies: 1
    Last Post: 2008-07-17, 06:39 AM
  4. Retrieve id of Contacts and Cases created from web form
    By smcnally in forum Developer Help
    Replies: 0
    Last Post: 2007-11-16, 08:11 PM
  5. Replies: 0
    Last Post: 2007-04-30, 07:09 PM

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
  •