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

Thread: Displaying information from other databases

  1. #1
    Danielg42 is offline Sugar Community Member
    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    187

    Lightbulb Displaying information from other databases

    Hello everyone.
    I've run into another issue with my custmization of Sugar.
    I need to have a custom field in the accounts module display the name of the sales person in charge of the account.
    The sales people are in charge of areas based on zip code. So basically I want to run a php script that checks the zip code of the currently opened account, then checks our sales person database for the name associated with that zip code. Unfortunately, my attempts to use a php script in a custom field have failed, so I need some other ideas.
    Is there any easy way to make this work?

  2. #2
    kbrill's Avatar
    kbrill is offline SugarCRM PS Engineer
    Join Date
    Jul 2004
    Location
    St Louis, MO
    Posts
    3,183

    Default Re: Displaying information from other databases

    can you post what you have tried so far? This would be a great use of a 'after_retrieve' logic hook script.
    Kenneth Brill - Help Forum Moderator

    I do not respond to 'Private Messages'. Please email me directly instead

    When asking for help, PLEASE give us your Server Information and Version Numbers as asked for on the 'Post New Message' screen as well as any JavaScript errors shown at the bottom of the browser window.
    Help us Help You

  3. #3
    andydreisch's Avatar
    andydreisch is offline Sugar Team Member
    Join Date
    Apr 2005
    Location
    San Jose
    Posts
    2,080

    Default Re: Displaying information from other databases

    Ideally the Studio s/b able to pull related field(s) based on current value, of Zip in this case.

    But ... I'll make sure to create a Wiki article basede on Danielg42's input.

    Andy
    Andy Dreisch
    Vice President, Online Team


    Check out our Podcasts!
    Sugar University for training
    Sugar Wiki for developer and user help
    SugarForge for modules, themes, lang packs
    SugarExchange for production-ready extensions
    Enter/view bugs via the Sugar bug tracker

  4. #4
    Danielg42 is offline Sugar Community Member
    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    187

    Default Re: Displaying information from other databases

    Well I haven't been able to get anything working properly in sugar and my knowledge of php is minimal.

    So don't laugh too hard.
    Here's the php required to display the zipcode and sales person in a table.
    Code:
    <?php
    
    mysql_connect("localhost", "root", "test") or die(mysql_error());
    mysql_select_db("sales") or die(mysql_error());
    
    $zipcode=92605;  //put sugarcrm's variable for the zipcode here
    
    $result = mysql_query("SELECT * FROM salespersons where zip=$zipcode") 
    or die(mysql_error());  
    
    echo "<table border='1'>";
    echo "<tr> <th>Zip</th> <th>Name</th> </tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    	// Print out the contents of each row into a table
    	echo "<tr><td>"; 
    	echo $row['zip'];
    	echo "</td><td>"; 
    	echo $row['sls_name'];
    	echo "</td></tr>"; 
    } 
    
    echo "</table>";
    mysql_close($con);
    ?>
    What I attempted was sticking that into an html custom field. Apparently the html field only displays html though.

    If you could explain more about the logic hook you were talking about, I'd be very grateful.

    @Andy
    What do you mean by the studio's s/b? Am I missing something obvious?
    Last edited by Danielg42; 2006-12-14 at 05:47 PM. Reason: Someone else slipped in a post

  5. #5
    kbrill's Avatar
    kbrill is offline SugarCRM PS Engineer
    Join Date
    Jul 2004
    Location
    St Louis, MO
    Posts
    3,183

    Default Re: Displaying information from other databases

    Quote Originally Posted by Danielg42
    Well I haven't been able to get anything working properly in sugar and my knowledge of php is minimal.

    So don't laugh too hard.

    What I attempted was sticking that into an html custom field. Apparently the html field only displays html though.

    If you could explain more about the logic hook you were talking about, I'd be very grateful.
    I see what you are trying to attempt. This is not a selection, just a list right?
    Kenneth Brill - Help Forum Moderator

    I do not respond to 'Private Messages'. Please email me directly instead

    When asking for help, PLEASE give us your Server Information and Version Numbers as asked for on the 'Post New Message' screen as well as any JavaScript errors shown at the bottom of the browser window.
    Help us Help You

  6. #6
    Danielg42 is offline Sugar Community Member
    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    187

    Default Re: Displaying information from other databases

    Hmm...
    Yea, I guess it would be a list.

  7. #7
    andydreisch's Avatar
    andydreisch is offline Sugar Team Member
    Join Date
    Apr 2005
    Location
    San Jose
    Posts
    2,080

    Default Re: Displaying information from other databases

    Quote Originally Posted by Danielg42
    ... Andy, What do you mean by the studio's s/b? Am I missing something obvious?
    Sorry. I think a nice addition to Studio screen layout editor (Admin -> Studio) would be the ability to identify and display related information based on the contents of a field value in the current record. In your case, defining a lookup of a rep's name based on the value of the ZIP field.

    Andy
    Andy Dreisch
    Vice President, Online Team


    Check out our Podcasts!
    Sugar University for training
    Sugar Wiki for developer and user help
    SugarForge for modules, themes, lang packs
    SugarExchange for production-ready extensions
    Enter/view bugs via the Sugar bug tracker

  8. #8
    leenwebb is offline Sugar Community Member
    Join Date
    Nov 2006
    Location
    New Hampshire
    Posts
    77

    Default Re: Displaying information from other databases

    I've done something pretty similar in my own sugar -- here's what I did (for DetailView):

    1) In custom/working/modules/****/DetailView.html, find the place you want the list to be. Then put in an xtpl variable as a placeholder, like "{ZIP_LIST}".

    2) Go to Studio and "Save and Publish" that layout ( Accounts -> DetailView, for example). That will take the custom/working file with its new variable and copy it to all the right places.

    3) In modules/****/DetailView.php , put your PHP in and declare a variable that contains all your HTML, let's say "$zipList". Then put in an xtpl line that will shove that variable over into the HTML. Like this:

    $xtpl->assign("ZIP_LIST", $zipList);

    My own sugar is full of things like this, and they've been working great for me. You can go way more complicated if you need to, using outside PHP queries to populate dropdowns and other things. Good luck!

    Eileen

  9. #9
    Danielg42 is offline Sugar Community Member
    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    187

    Default Re: Displaying information from other databases

    Thanks a lot everyone.
    Kbrill has offered to help me out by writing a module for me.
    However, all of this information has been extremely helpful by increasing my knowledge of how sugar works.

  10. #10
    Danielg42 is offline Sugar Community Member
    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    187

    Default Re: Displaying information from other databases

    I've got it working through your method leenwebb.
    Thanks.

    The only issue is it seems to have broken the studio. In order to use the studio, I have to remove my php, use it, then put my php back in. Besides that, there are no real problems.

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)

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
  •