Results 1 to 3 of 3

Thread: automatic assignment to creator user

  1. #1
    mikrob35 is offline Senior Member
    Join Date
    Sep 2008
    Posts
    22

    Default automatic assignment to creator user

    Hi all,

    I want the account to be automatically assigned to the user who created it (therefore, I don't want to give my users the possibility to choose the assigned_user of the account they create).

    In this post , I found a way to eliminate the "assigned to" field from the create form, but then it won't assign the account to anybody...and I want the record to be automatically assigned to its creator.


    Would anybody have a solution?

    Thanks a lot in advance.

  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: automatic assignment to creator user

    Hi mikrob35

    After removing the assigned_user_name from the form you need to create a logic_hook before save for the modules you had removed the assigned_user_name. In this logic_hook you set the assigned_user_name as the user who created ($current_user).

    code for custom/modules/Accounts/logic_hooks.php:
    PHP Code:
    $hook_version 1;
    $hook_array = Array();

    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1'setAssignedUserName''custom/modules/Accounts/AccountLogicHook.php''AccountLogicHook''setAssignedUserName'); 
    code for custom/modules/Accounts/AccountLogicHook.php:
    PHP Code:
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class 
    AccountLogicHook {
        function 
    setAssignedUserName(&$focus$event$arguments) {
            
    $query "SELECT * FROM accounts WHERE id = '{$focus->id}'";
            
    $result $focus->db->query($querytrue);
        
            if(
    $focus->db->getRowCount($result) == 0) {
                global 
    $current_user;
            
                
    $focus->assigned_user_id $current_user->id;
            }
        }

    Best regards
    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
    mikrob35 is offline Senior Member
    Join Date
    Sep 2008
    Posts
    22

    Thumbs up Re: automatic assignment to creator user

    It worked like a charm.

    New to Sugar, I'm gonna learn more about logic hooks in the wiki.

    Thanks a lot Andopes for your precious and precise help

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 2008-05-20, 09:52 PM
  2. Assignment Notification - Not Sent
    By absando in forum General Discussion
    Replies: 5
    Last Post: 2007-02-21, 07:42 AM
  3. Replies: 2
    Last Post: 2006-11-07, 05:48 PM
  4. automatic role assignment
    By Loerincz in forum Developer Help
    Replies: 2
    Last Post: 2006-06-14, 04:04 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
  •