Results 1 to 7 of 7

Thread: SQL manually fill table like accounts_opportunities

  1. #1
    wivaku is offline Sugar Community Member
    Join Date
    Oct 2006
    Posts
    38

    Default SQL manually fill table like accounts_opportunities

    Hi all,

    Environment: SugarPro 5.2.0c with MySQL 4.

    Trying to populate a joint table, similar to accounts_opportunities.
    Example: accounts and awards. With Studio I created the tables and relationships,
    left to do: import existing data.

    For my accounts_awards table, I have the fields: id, date, acccount_id, award_id.
    The account_id and award_id combinations I can take care of, same for the date field.

    The question: what is the recommended / required way to generate the id key?
    Sorry in advance if this is a very basic question!

    Thanks in advance,

    -Winfred

  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: SQL manually fill table like accounts_opportunities

    The id key can be generated using the MySQL function UUID().

    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
    wivaku is offline Sugar Community Member
    Join Date
    Oct 2006
    Posts
    38

    Default Re: SQL manually fill table like accounts_opportunities

    I was hoping it was something simple like that.
    Thanks for taking the time to answer such a basic question!

  4. #4
    wivaku is offline Sugar Community Member
    Join Date
    Oct 2006
    Posts
    38

    Default Re: SQL manually fill table like accounts_opportunities

    Ok André (and others), I feel bad for asking such a basic question before, so... let's make it a little bit more tough. :-)

    What is the SQL/PHP code to achieve the following?

    Pseudo code:
    - for each <opportunity_id> from opportunities
    - where team_id = <team_id_xyz>
    - and my_custom_field = <partner_id>
    - create record in accounts_specialopps
    - set:
    id = uuid()
    date = now
    account_id = <partner_id>
    opportunity_id = <opportunity_id>

    Thanks in advance!

  5. #5
    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: SQL manually fill table like accounts_opportunities

    The code is something like that:

    Code:
    INSERT INTO accounts_apecialopps (id, date, account_id, opportunity_id)
    (
    SELECT UUID(), NOW(), oc.my_custom_field, o.id
    FROM opportunities AS o
    INNER JOIN opportunities_cstm AS oc ON o.id = oc.id_c
    WHERE o.team_id = '<team_id_xyz>' AND oc.my_custom_field = '<partner_id>'
    )
    Perhaps you need to modify something.

    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.

  6. #6
    wivaku is offline Sugar Community Member
    Join Date
    Oct 2006
    Posts
    38

    Default Re: SQL manually fill table like accounts_opportunities

    Super! Thanks André for the excellent and fast assistance. Me happy. :-)

  7. #7
    cmacholz is offline Senior Member
    Join Date
    Sep 2009
    Location
    Missoula, MT
    Posts
    82

    Default Re: SQL manually fill table like accounts_opportunities

    One more question,

    if you insert a new record and you want to TRACK that action in the tracker table...what value would go in the monitor_id field?


    INSERT INTO tracker (monitor_id
    ,user_id
    ,module_name
    ,item_id
    ,item_summary
    ,date_modified
    ,action
    ,session_id )
    VALUES ( '3c9ef974-5a28-698f-6ce5-4c114c1d075d'
    ,'d5056d8f-3844-6e26-301a-4acf9d3053ea'
    ,'Contacts'
    ,'5d7f76f3-f30e-bf7d-9b85-4c114c69e07c'
    ,'Test 2'
    ,'2010-06-10 20:33:41'
    ,'save'
    ,'d8rgbbv08v4deos0vgmh794s17')

    THANKS!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Fill in list fields
    By jmugauri in forum Developer Help
    Replies: 4
    Last Post: 2010-09-25, 06:06 AM
  2. How fill the new field with a new fields ?
    By krakoss2 in forum Developer Help
    Replies: 5
    Last Post: 2008-01-14, 04:09 PM
  3. Fill in a custom field
    By YamilBracho in forum Help
    Replies: 6
    Last Post: 2007-10-09, 02:18 AM
  4. Manually Add Field to contacts table
    By mlh in forum Developer Help
    Replies: 9
    Last Post: 2006-08-16, 10:53 PM
  5. Replies: 11
    Last Post: 2006-01-18, 05:44 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
  •