Results 1 to 8 of 8

Thread: Generating entries via hook????

  1. #1
    michamamo2 is offline Senior Member
    Join Date
    Sep 2008
    Posts
    64

    Default Generating entries via hook????

    Hi,


    Is it possible to generate new entries or change existing entries in a customized module using a logical hook?
    - if yes, how does it work (especially generating the new entry)?
    - I think I can change the entries using some sql code in php ... ... right?

    Micha

  2. #2
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,467

    Default Re: Generating entries via hook????

    Quote Originally Posted by michamamo2
    Hi,


    Is it possible to generate new entries or change existing entries in a customized module using a logical hook?
    - if yes, how does it work (especially generating the new entry)?
    - I think I can change the entries using some sql code in php ... ... right?

    Micha
    You can generate new entries or amend existing ones

    Both are done using sql
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk]www.ivy.ltd.uk

    php version 5.2.6
    MySql 5.1.59

  3. #3
    dwheeler is offline Sugar Team Member
    Join Date
    Sep 2007
    Location
    Cupertino CA
    Posts
    165

    Default Re: Generating entries via hook????

    New entries can/should be created from a logic hook without directly interfacing with the database by create a new instance of the SugarBean of your the module, setting the values on that bean, and then calling the beans save() function.

    Example using Accounts:
    PHP Code:
    require_once("modules/Accounts/Account.php");
    $temp_account = new Account();
    $temp_account->name "My new account";
    $temp_account->save(); 
    Similarly, if you wanted to change an existing account, you can call
    PHP Code:
    $temp_account->retrieve($id
    after creating the new Account object and before making any changes
    - David Wheeler
    Software Engineer

  4. #4
    michamamo2 is offline Senior Member
    Join Date
    Sep 2008
    Posts
    64

    Default Re: Generating entries via hook????

    Hi,

    that sounds good - what I want is to create entries for a new module (copied from opportunities) every time an opportunity is saved. I assume I will have to call the retrieve function and define the mandatory data (out of the opportunity data) like done in your example with the name for accounts.
    Is this a plausible solution?

    Greetings from Germany
    Micha

  5. #5
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Generating entries via hook????

    Yes that's correct.
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  6. #6
    michamamo2 is offline Senior Member
    Join Date
    Sep 2008
    Posts
    64

    Default Re: Generating entries via hook????

    Hi,

    my hook works quite good in creating new entries in my customized module. But there's still one problem:

    The new module was copied from the opportunity module and it needs an entry in the "date_closed" field. Just copying the field doesn't seem to work

    In the hook function I defined:
    $temp_[New_Module]->date_closed = $focus->date_closed

    This always leads to 01/01/2000 in the date_closed field of the new module.

    What can I do to copy the real "date_closed"?

    Micha

  7. #7
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Generating entries via hook????

    Yeah, hooks and date field don't really match...don't have a solution right now but you could try using $focus->fetched_row['date_closed'] instead.
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  8. #8
    michamamo2 is offline Senior Member
    Join Date
    Sep 2008
    Posts
    64

    Default Re: Generating entries via hook????

    Hi,

    my hook is working now, including the date fields.
    It will work if the date formatting is same for all users (which I am responsible for):
    $temp_[new_module]->date_closed = $help5."/01/".$help6;
    (by defining the date format to mm/dd/yyyy and using integer variables $helpX to calculate year and month)

    By the way: If I change the config.php in a way, that only one dateformat is allowed, is it right, that then the users have to use this dateformat and that the hook should be save if it can manage this dateformat?

    Now there's a second question:
    I want to delete some entries in a submodule with the same hook ....

    OK, I need to update the relationship table and the new created table with deleted = 1 - but do I need to do thisg via SQL (I have a query for that running in my database environment) or is there another solution using Sugar functionality?

    Any ideas?

    Micha
    Last edited by michamamo2; 2008-10-02 at 09:25 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Subpanel NOT displaying duplicate entries
    By Durrill in forum Developer Help
    Replies: 2
    Last Post: 2012-03-29, 10:46 AM
  2. Getting number of entries in a module using SOAP Call
    By pvikasroonwal in forum Developer Help
    Replies: 0
    Last Post: 2008-04-02, 08:28 AM
  3. CarouselCRM Installation
    By StevenE in forum Installation and Upgrade Help
    Replies: 0
    Last Post: 2007-08-30, 08:16 AM
  4. Adding Logic Hook to existing
    By Superman in forum Developer Help
    Replies: 2
    Last Post: 2006-12-18, 09:38 PM
  5. Logic Hook Question
    By swhitlow in forum Developer Help
    Replies: 1
    Last Post: 2006-06-04, 04:49 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
  •