Results 1 to 6 of 6

Thread: soap insert and update record

  1. #1
    eitrix's Avatar
    eitrix is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Serbia
    Posts
    396

    Post soap insert and update record

    Heya, i have started working with soap and if someone is able to share code they use for login/insert/update i think whole community would appreciate it. I have been looking around and tbh info ain't that great especially on updating a record.

    Thank you all.
    CRM Software Engineer
    Eontek - www.eontek.rs

  2. #2
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: soap insert and update record

    I use the nusoap client. I'm just going to post code because that's all you asked for but if you need a further explanation I'd be happy to oblige.

    To login:

    Notes:
    -The user and password are the same you would use to login to SugarCRM
    -Your password has to be md5 encripted (PHP comes with an md5() function).
    -Its a really good idea to store your session id as this is used in moth other functions.
    -your wsdl url should include the '?wsdl' at the end of it.
    Code:
    PHP Code:
    inculde_once('path/to/nusoap.php');

    $client = new nusoap_client($wsdl,true);
        
    //login
    $auth_array = array(
        
    'user_name' => $username,
        
    'password' => $password,
        
    'version' => '0.1'
    );

    $login_params = array('user_auth' => $auth_array,
        
    'application_name' => 'WebForm');

    $login_results $client->call('login',$login_params);
        
    $session_id =  $login_results['id']; 
    Insert:

    Notes:
    -You must have a session id

    PHP Code:
    $set_entry_params = array(
        
    'session' => $session_id,
        
    'module_name' => 'Leads',
        
    'name_value_list' => array(
            array(
    'name' =>'email1'
                
    'value' => $_REQUEST['webtolead_email1']),
            array(
    'name' =>'first_name'
                
    'value' => $_REQUEST['first_name']),
            array(
    'name' =>'last_name'
                
    'value' => $_REQUEST['last_name']),
            array(
    'name' =>'title'
                
    'value' => $_REQUEST['title']),
            array(
    'name' =>'account_name'
                
    'value' => $_REQUEST['account_name']),
            array(
    'name' =>'phone_work'
                
    'value' => $_REQUEST['phone_work']),
            array(
    'name' =>'website'
                
    'value' => $_REQUEST['website']),
            array(
    'name' =>'lead_source'
                
    'value' => 'Web Site'),
            array(
    'name' => 'status'
                
    'value' => 'Inactive')
            )
        );
            
    $set_entry_result $client->call('set_entry'$set_entry_params); 
    Update:

    Notes:
    -You must have a session id.
    -Updating is a two step process. You must first find the entry you want to update. In this case I'm searching my Contacts and Leads module for a record with a given email (assuming I have a unique email for every contact/lead). Then, you do the same thing you would for an insert, except in your name/value pairs you MUST add the record id.

    Code:
    PHP Code:
    //Search leads and contacts
    $search_by_module_params = array(
        
    'user_name' => $username,
        
    'password' => $password,
        
    'search_string' => $_REQUEST['m_email'],
        
    'modules' => array('Contacts''Leads'),
        
    'offset' => 0,
        
    'max_results' => '1'
        
    );
        
    $search_by_module_result $client->call('search_by_module'$search_by_module_params);

    $entryid $search_by_module_result['entry_list'][0]['id'];

    $nvl = array(
        array(
    'name' => 'id',
            
    'value' => $entryid),
        array(
    'name' =>'email1'
            
    'value' => $_REQUEST['m_email']),
        array(
    'name' =>'first_name'
            
    'value' => $_REQUEST['m_first_name']),
        array(
    'name' =>'last_name'
            
    'value' => $_REQUEST['m_last_name']),
        array(
    'name' =>'title'
            
    'value' => $_REQUEST['m_title']),
        array(
    'name' =>'account_name'
            
    'value' => $_REQUEST['m_company']),
        array(
    'name' =>'phone_work'
            
    'value' => $_REQUEST['m_phone']),
        array(
    'name' =>'set_opt_c'
            
    'value' => $_REQUEST['m_opt_out']),
        array(
    'name' =>'flag_opt_c'
            
    'value' => '1'),
        array(
    'name' =>'website'
            
    'value' => $_REQUEST['m_website'])
            );

    $set_entry_params = array(
        
    'session' => $session_id,
        
    'module_name' => $search_by_module_result['entry_list'][0]['module_name'],
        
    'name_value_list' => $nvl);

    $set_entry_result $client->call('set_entry'$set_entry_params); 
    If any of your functions aren't working, you can always print_r() the response that you get from $client->call() to see if there are any errors. Let me know if you have any questions.
    Robert Beckman
    Software Engineer
    Mirth Corporation

  3. #3
    eitrix's Avatar
    eitrix is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Serbia
    Posts
    396

    Default Re: soap insert and update record

    Thank you very much for the code provided, i will be testing it out and report my results.

    One question, are you using nusoap.php included with sugar or you use diffrent library?

    i ask this becouse in initial testing i'm having problems loging in becouse i get version missmatch when using nusoap from include folder.

    I'm using sugar 6 ent edition.
    Last edited by eitrix; 2010-08-30 at 04:20 PM.
    CRM Software Engineer
    Eontek - www.eontek.rs

  4. #4
    eitrix's Avatar
    eitrix is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Serbia
    Posts
    396

    Default Re: soap insert and update record

    edited above post
    CRM Software Engineer
    Eontek - www.eontek.rs

  5. #5
    eitrix's Avatar
    eitrix is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Serbia
    Posts
    396

    Question Re: soap insert and update record

    Ok, i have managed to get it working so far. Inserting a new record and updating works great. What i am having problems is setting up the relationship between 2 modules.

    For example i want to set relatinship between the opportunitie i made and a call, so call shows in activities subpanel of opportunitie.

    I have tried code like this, and many variations but nothings seems to work, i either get error
    Array ( [number] => 20 [name] => Module Does Not Exist [description] => This module is not available on this server )

    or nothing shows up.

    PHP Code:
    $rl = array(
        
    'session' => $session_id,
        
    'set_relationship_value' => array(
        
    'module_name' => 'Calls',
        
    'module_id' => $resultCaId['id'],
        
    'link_field_name' => 'parent_id',
        
    'related_ids' => array($resultOpId['id']),
        )
    );
    $resultRel $client->call('set_relationship',$rl);
    echo 
    '<br />';
    print_r($resultRel); 
    or without that set_relationship_value array so it looks like this

    PHP Code:
    $rl = array(
        
    'session' => $session_id,
        
        
    'module_name' => 'Calls',
        
    'module_id' => $resultCaId['id'],
        
    'link_field_name' => 'parent_id',
        
    'related_ids' => array($resultOpId['id']),
        
    );
    $resultRel $client->call('set_relationship',$rl);
    echo 
    '<br />';
    print_r($resultRel); 
    CRM Software Engineer
    Eontek - www.eontek.rs

  6. #6
    eitrix's Avatar
    eitrix is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Serbia
    Posts
    396

    Talking Re: soap insert and update record

    Just to share with everyone, here is a solution that worked.

    PHP Code:
    $rl = array(

    // session id from login
        
    'session' => $session_id,
        
    'set_relationship_value' => array(

    // put here the module that shows subpanel in 1:n relationships, in this case Calls is subpanel in opportunity
        
    'module1' => 'Opportunities',
        
    'module1_id' => $resultOpId['id'],

    // put here the other module you are relating to
        
    'module2' => 'Calls',
        
    'module2_id' => $resultCaId['id'],
        
        )
    );
    // call to set relationship
    $resultRel $client->call('set_relationship',$rl);
    echo 
    '<br />';
    // print test results
    print_r($resultRel); 
    My working edition is sugar 6 ent and i have included in file nusoap.php from sugarcrm include/nusoap/nusoap.php
    CRM Software Engineer
    Eontek - www.eontek.rs

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. insert record
    By neel1154 in forum Developer Help
    Replies: 6
    Last Post: 2010-06-25, 02:36 PM
  2. Replies: 0
    Last Post: 2010-04-28, 02:19 AM
  3. SOAP update/insert problem
    By ivit in forum Developer Help
    Replies: 1
    Last Post: 2010-02-23, 11:01 AM
  4. Hi How to get last insert record id
    By vimal123 in forum Developer Help
    Replies: 0
    Last Post: 2009-10-09, 01:47 PM
  5. How to add a new record or update a record in Sugar
    By Arpan_Biswas in forum Developer Help
    Replies: 0
    Last Post: 2006-02-08, 10:47 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
  •