Results 1 to 10 of 10

Thread: Soap question...how to retrieve a lead...

  1. #1
    tradeangle is offline Member
    Join Date
    Sep 2008
    Posts
    6

    Default Soap question...how to retrieve a lead...

    Hi guys,

    I can insert leads using SOAP easily, but I cannot find any examples of retrieving a lead row using a basic search.

    For example, I want to search our leads for, say, last name. All i want to do is search leads for a certain last name, then read a value from another field in that row. So, say I search for "Picklefeather" as last name..and i want to see what picklefeather's phone number is.

    Can anyone give maybe a code snippet to demonstrate? Ive looked in the wiki, the beanizer page, etc....and the examples. Nothing like this is really demonstrated.

    Thanks!

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Soap question...how to retrieve a lead...

    Hi tradeangle

    If you wan to retrieve a lead based on its id you can use the get_entry, if you want to retrieve from some other fields you can use the get_entry_list.

    You can find good examples of this functions into VeryThinClient project at SugarForge.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    tradeangle is offline Member
    Join Date
    Sep 2008
    Posts
    6

    Default Re: Soap question...how to retrieve a lead...

    Code:
      $get_entry_params = array(
                       'session' => $session_id,
                         'module_name' => 'Contacts',
    			'query' => "first_name = 'Joe'",
    			'max_results' => '5',
    			'select_fields' => "first_name"
    			);
    
     $result = $soapclient->call('get_entry_list',$get_entry_params);
    
    print_r($result);

    This gives me a blank screen. Idea ideas?

  4. #4
    darcy.rippon is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    121

    Default Re: Soap question...how to retrieve a lead...

    the result is an array, which is quite convoluted to navigate!

    Here's what I did
    Code:
    //query by app_id
    $app_id = $_POST['app_id'];
    $query = "id='$app_id'";
    
    $result = $soapclient->call('get_entry_list',array('session'=>$session_id,'module_name'=>'custom_Leadt','query'=>$query,'order_by'=>'','offset'=>0, 'select_fields'=>array('first_name','last_name','email1')));
    
    //write the result into an array
    $my_array = array();
    
    foreach($result['entry_list'] as $new_array){
    	foreach($new_array['name_value_list'] as $final_array) {
    		$my_array[$final_array['name']] = $final_array['value'];
    		//echo $final_array['name'] . " = " . $final_array['value'] . "<br>";
    		};
    };
    echo $my_array['first_name'];
    I think you need to put your query params into an array.

    I hope this helps.

  5. #5
    tradeangle is offline Member
    Join Date
    Sep 2008
    Posts
    6

    Default Re: Soap question...how to retrieve a lead...

    Thanks for your reply. I ran your code and changed very minor things to reflect my situation, but got a

    Warning: Invalid argument supplied for foreach() in C:\[server]\test.php on line 62


    error. Hmm...i will continue playing with it though.

  6. #6
    DigiCRM is offline Senior Member
    Join Date
    Sep 2008
    Posts
    84

    Default Re: Soap question...how to retrieve a lead...

    $module_name='Module name';
    $query='';
    $order_by='';
    $offset=0;
    $select_fields=array(
    'id',
    'case_number',
    'name',
    'status',
    );
    $max_results='200';
    $deleted=0;


    $search_list=$client->call('get_entry_list',array("session"=>$session_i d,"module_name"=>$module_name," query"=>$query,"order_by"=>$order_by,
    "offset"=>$offset," select_fields"=>$select_fields,"max_results"=>$max _results,"deleted"=>$deleted));

    function nameValuePairToSimpleArray($array){
    $my_array=array();
    while(list($name,$value)=each($array)){
    $my_array[$value['name']]=$value['value'];
    }
    return $my_array;
    }

    foreach($search_list['entry_list'] as $record){
    $array= nameValuePairToSimpleArray($record['name_value_list']);
    echo $array['Field name'];

    }

    in this case module name andselected fields and field name(Bold letter) can replace with u r needs ,and check

  7. #7
    tradeangle is offline Member
    Join Date
    Sep 2008
    Posts
    6

    Default Re: Soap question...how to retrieve a lead...

    Thanks foryour response, but im still getting the Warning: Invalid argument supplied for foreach() error.

  8. #8
    tradeangle is offline Member
    Join Date
    Sep 2008
    Posts
    6

    Default Re: Soap question...how to retrieve a lead...

    Whenevr i run Soaptest.php that comes with Sugar, in the Results part when they call 5 Contacts, i get a ton of info like this: HERE IS RESULT:
    Array ( [result_count] => 1 [next_offset] => 1 [field_list] => Array ( [0] => Array ( [name] => id [type] => id [label] => ID: [required] => 0 [options] => Array ( ) ) [1] => Array ( [name] => date_entered [type] => datetime [label] => Date Created [required] => 0 [options] => Array ( ) ) [2] => Array ( [name] => date_modified [type] => datetime [label] => Date Modified: [required] => 0 [options] => Array ( ) ) [3] => Array ( [name] => modified_user_id [type] => assigned_user_name [label] => Modified By Id [required] => 0 [options] => Array ( ) ) [4] => Array ( [name] => modified_by_name [type] => assigned_user_name [label] => Modified By Id [required] => 0 [options] => Array ( ) ) [5] => Array ( [name] => created_by [type] => assigned_user_name [label] => Created By Id [required] => 0 [options] => Array ( ) ) [6] => Array ( [name] => created_by_name [type] => assigned_user_name [label] => Created By Id [required] => 0 [options] => Array ( ) ) [7] => Array ( [name] => description [type] => text [label] => Description: [required] => 0 [options] => Array ( ) ) [8] => Array ( [name] => deleted [type] => bool [label] => Deleted [required] => 0 [options] => Array ( ) [default_value] => 0 ) [9] => Array ( [name] => assigned_user_id [type] => relate [label] => Assigned User [required] => 0 [options] => Array ( ) ) [10] => Array ( [name] => assigned_user_name [type] => relate [label] => Assigned User [required] => 0 [options] => Array ( ) ) [11] => Array ( [name] => team_id [type] => team_list [label] => Team ID: [required] => 0 [options] => Array ( ) ) [12] => Array ( [name] => team_name [type] => relate [label] => Team [required] => 0 [options] => Array ( ) ) [13] => Array ( [name] => salutation [type] => enum [label] => Salutation: [required] => 0 [options] => Array ( [0] => Array ( [name] => [value] => ) [1] => Array ( [name] => Mr. [value] => Mr. ) [2] => Array ( [name] => Ms. [value] => Ms. ) [3] => Array ( [name] => Mrs. [value] => Mrs. ) [4] => Array ( [name] => Dr. [value] => Dr. ) [5] => Array ( [name] => Prof. [value] => Prof. ) ) ) [14] => Array ( [name] => first_name [type] => varchar [label] => First Name: [required] => 0 [options] => Array ( ) ) [15] => Array ( [name] => last_name [type] => varchar [label] => Last Name: [required] => 1 [options] => Array ( ) ) [16] => Array ( [name] => title [type] => varchar [label] => Title: [required] => 0 [options] => Array ( ) ) [17] => Array ( [name] => department [type] => varchar [label] => Department: [req

  9. #9
    tradeangle is offline Member
    Join Date
    Sep 2008
    Posts
    6

    Default Re: Soap question...how to retrieve a lead...

    Hi guys....i finally figured it out. lol. The above poster is right -- the response is so convoluted that it's very difficult to get what data you need. And my way may not be the best way, but it worked when nothing else did. Also, for me, "select_fields" did NOT work at all. It returned every single field for that record...which is fine, it's just SO convoluted.

    I had to print_r the entire result to decipher what it returned.

    I discovered how the multidimensional is formed, and saw I had to find the number of the field I wanted.

    Basically if you do your call to get_entry_list, and you put the data into, say, $result...

    then to access a field in one of the results, i did something like this, which was based off of one of the above poster's code:

    if ($result['result_count'] >= "1") {

    foreach($result['entry_list'] as $new_array){

    $new_array['name_value_list']['170']['value'] // this value 170, for example, is my custom field i wanted to access

    } // end foreach

    ) // end if




    I know that probably doesnt make sense, because ive left out most of my code...but it sort of shows the odd data structure it returns. The nesting can be described as follows: $result -> 'entry_list' -> 'name_value_list' -> [the NUMBER of the field] -> 'value'



    The number of the field you can find by print_r the $result array.


    Hope this can maybe help any future searchers.

  10. #10
    joshasbury is offline Junior Member
    Join Date
    Nov 2008
    Posts
    3

    Default Re: Soap question...how to retrieve a lead...

    I am trying to base my solution on yours, but unfortunately, I am coming up empty. What I'm trying to do is see if an Account by a name already exists before creating a new one. So, I create an account name string and add it to a query string called $query_str

    When I pass the $query_str, I get no results returned even if there is a record in the DB with that information. If I just make 'query'=>'' in my soapclient call, I get all of the accounts returned in an array (which is what I'd expect). So, what I'd really like to do is just see if *anything* at all gets returned and not create an account if that happens. Any idea what I might be doing wrong here? It should be simple enough

    $account_name_str = $_POST['ht_first_name_c'] . " " . $_POST['ht_last_name_c'];
    $query_str = 'name = "' . $account_name_str . '"';
    // look for a particular account name and then get its ID
    echo '<br><br><b>Get list of Accounts:</b><BR>';
    $result = $soapclient->call('get_entry_list',array('session'=>$session_i d,'module_name'=>'Accounts','query'=>$query_str));

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. SOAP Convert lead to contact/account
    By dvancamp in forum Developer Help
    Replies: 6
    Last Post: 2011-08-25, 07:04 PM
  2. SOAP API, Java -- Creating and submitting a lead?
    By sugarmichael in forum Developer Help
    Replies: 5
    Last Post: 2008-06-27, 04:43 PM
  3. Retreiving emails related to lead via SOAP
    By kent13304 in forum Developer Help
    Replies: 3
    Last Post: 2007-04-19, 12:36 AM
  4. Replies: 1
    Last Post: 2007-02-11, 09:25 PM
  5. From lead to order
    By george_bbch in forum Feature Requests
    Replies: 0
    Last Post: 2006-09-26, 02:02 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
  •