Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: How to restrict the drop down values based on Role?

  1. #1
    bands is offline Sugar Community Member
    Join Date
    Aug 2006
    Posts
    41

    Default How to restrict the drop down values based on Role?

    Hi

    am using using sugar 4.2.*, i want to restrict the drop down values based on the role.how to do this. plz guide me.

    regards.
    BSK

  2. #2
    mycrmspacegunnar is offline Sugar Community Member
    Join Date
    Sep 2006
    Posts
    105

    Default Re: How to restrict the drop down values based on Role?

    Hi,

    I fear what you want to do is not possible with sugar.


    Cheers
    Gunnar
    Gunnar von Boehn
    myCRMspace

  3. #3
    sacramentojoe is offline Sugar Community Member
    Join Date
    Nov 2005
    Posts
    447

    Default Re: How to restrict the drop down values based on Role?

    Quote Originally Posted by bands
    Hi

    am using using sugar 4.2.*, i want to restrict the drop down values based on the role.how to do this. plz guide me.

    regards.
    BSK
    Hi there, we did this in the EditView.php file.
    If you notice that all drop downs / Selects are built within this page.

    What I did was setup seperate drop down arrays and based off ot the Role, is which one got loaded.

    Let me know if you need more help, I'll show you some code.

  4. #4
    malcolmh's Avatar
    malcolmh is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Aug 2004
    Posts
    1,712

    Default Re: How to restrict the drop down values based on Role?

    Hi,

    I think this is something that would also be interesting for other users. Could you post what you did here? It would be something that should also be put in the SugarWiki.

    Are the modifications safe from new versions and patches?
    Cheers Malcolm

    Genius4U Limited - Ingenious simple IT solutions for you / Genial einfache IT Lösungen für Sie
    http://www.genius4u.com or http://www.genius4u.de

  5. #5
    sacramentojoe is offline Sugar Community Member
    Join Date
    Nov 2005
    Posts
    447

    Default Re: How to restrict the drop down values based on Role?

    Quote Originally Posted by malcolmh
    Hi,

    I think this is something that would also be interesting for other users. Could you post what you did here? It would be something that should also be put in the SugarWiki.

    Are the modifications safe from new versions and patches?
    I'll try to write it up in a format that will make it easy for all to follow.
    I believe the code to be mod & version safe with the exception of adding a new EditView.php file and lead.php (my example, we used lead).

    I'm almost done with the document. If it's something that gets added to the Wiki, who makes that decision? How can I submit it to be added to the Wiki?
    Last edited by sacramentojoe; 2006-12-13 at 01:11 AM.

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

    Default Re: How to restrict the drop down values based on Role?

    Hi sacramentojoe, this enhancement you have sounds terrific.

    The Sugar Wiki is available for any community member to extend and enhance. If you need assistance then just shout out and we can help. Wiki syntax examples are rampant across the web but we can help if need be.

    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

  7. #7
    sacramentojoe is offline Sugar Community Member
    Join Date
    Nov 2005
    Posts
    447

    Default Re: How to restrict the drop down values based on Role?

    Quote Originally Posted by andydreisch
    Hi sacramentojoe, this enhancement you have sounds terrific.

    The Sugar Wiki is available for any community member to extend and enhance. If you need assistance then just shout out and we can help. Wiki syntax examples are rampant across the web but we can help if need be.

    Andy
    Hi Andy, I'm new to the whole Wiki idea so I'll definitely need some assistance.
    I have a rough draft written but I'm going to spend some more time going over the details and making sure that I didn't miss anything.

    Joe

  8. #8
    bands is offline Sugar Community Member
    Join Date
    Aug 2006
    Posts
    41

    Default Re: How to restrict the drop down values based on Role?

    Quote Originally Posted by sacramentojoe
    Hi there, we did this in the EditView.php file.
    If you notice that all drop downs / Selects are built within this page.

    What I did was setup seperate drop down arrays and based off ot the Role, is which one got loaded.

    Let me know if you need more help, I'll show you some code.
    Hi

    can u show me some code...so that i can proceed..

    thanks
    bsk

  9. #9
    sacramentojoe is offline Sugar Community Member
    Join Date
    Nov 2005
    Posts
    447

    Default Re: How to restrict the drop down values based on Role?

    OK, here is my attempt to explain this. If there is an easier / cleaner way to do this, feel free to let me know.
    How to Add Role Restriction to a Drop Down

    The first thing I did was create three (3) drop downs.
    I prefer to manually create them but you can create them via the studio if you’d like.

    Here is what my /custom/include/language/en_us.lang.php file looks like
    This first drop down is going to be the drop down that I use when I create my custom field. I chose to have the main drop down contain all of the values. If for some reason the logic I’m going to build was to fail, the user will be able to see all of the options. You could just as easily make this one value such as ‘Default’. It’s up to you.

    Code:
    $app_list_strings[‘role_select_dom’] = array(
    ‘Manager View 1’ => ‘Manager View 1’,
    ‘Manager View 2’ => ‘Manager View 2’,
    ‘Regular View 1’ => ‘Regular View 1’,
    ‘Regular View 2’ => ‘Regular View 2’,);
    This is the drop down list that will get loaded if they have manager view.
    Code:
    $app_list_strings[‘manager_role_select_dom’] = array(
    ‘Manager View 1’ => ‘Manager View 1’,
    ‘Manager View 2’ => ‘Manager View 2’,);
    This is the drop down list that will get loaded if they have a non-manager view.
    Code:
    $app_list_strings[‘regular_role_select_dom’] = array(
     ‘Regular View 1’ => ‘Regular View 1’,
    ‘Regular View 2’ => ‘Regular View 2’,);
    For this example, I’ll be using the lead module.
    I went through the Studio to create my custom field.
    I chose a drop down as the custom field type and I selected the “role_select_dom” as the drop down to use. I named my custom field “role_select”. Again, this will be loading ALL of the values by default. I then proceeded to add this new custom field to the EditView.html and DetailView.html of the Lead module. I also did this via the Studio.
    If you open up the EditView.html, you’ll see a line similar to this.
    Code:
    <select name=”role_select_c”>{OPTIONS_ROLE_SELECT_C}</Select>
    This line tells us 2 things.
    1. The name of our custom field is actually role_select_c.
    2. The options for the select come from OPTIONS_ROLE_SELECT_C and this is what we'll be over riding.

    Now that I know the name of the custom field, I added it to the variable list in the Lead.php file

    Code:
    var $role_select_c ;
    This is necessary as it maps the custom field to a member variable that we can reference later.

    The next step is to edit EditView.php.
    All custom fields are loaded with this statement.If you look in EditView.php for OPTIONS_ROLE_SELECT_C, you will not see it. It's built in the background by calling this script.
    //Add Custom Fields
    Code:
    require_once('modules/DynamicFields/templates/Files/EditView.php');
    Since our field is custom, we’ll want to make changes AFTER this line in order to over-ride the value.

    I borrowed the next bit of Code from a post where Julian gives an example to check for roles.
    http://sugarcrm.com/forums/showthread.php?t=9829

    Code:
    $role_to_check = "Team Manager"; // change this to the name of the role that you want to do a check on
    
    global $current_user; // grab the $current_user object
    require_once("modules/ACLRoles/ACLRole.php");
    $acl_role_obj = new ACLRole();
    
    $user_roles = $acl_role_obj->getUserRoles($current_user->id); // grab a list of the current user's roles
    
    $user_in_role = FALSE;
    foreach ($user_roles as $role) {
    	if ($role->name == $role_to_check) { // is the user in the role we're trying to restrict?
    		$user_in_role = TRUE;
    		break;
    	}
    }
    //If the user is in the role, display the Manager view dropdown
    //Here, we’re over riding the OPTIONS_ROLE_SELECT_C, notice how we’re now referencing the role_select_c variable that we added to Lead.php
    if ($user_in_role) {
    $xtpl->assign("OPTIONS_ROLE_SELECT_C",get_select_options_with_id($app_list_strings['manager_role_select_dom],$focus->role_select_c));
    }else{
    //User is not in role, display the regular / default values
    $xtpl->assign("OPTIONS_ROLE_SELECT_C",get_select_options_with_id($app_list_strings['regular_role_select_dom'],$focus->role_select_c));	
    }
    That's all there is to it. You could also get away with creating 2 drop downs, one for manager view and one for default view and only switch the manager view if the manager is loaded. As usual, there is more than one way to get things done but here is how I did it.
    Last edited by sacramentojoe; 2006-12-13 at 05:01 PM.

  10. #10
    bands is offline Sugar Community Member
    Join Date
    Aug 2006
    Posts
    41

    Default Re: How to restrict the drop down values based on Role?

    Hi sacramentojoe


    Thanks for ur quick reply....


    regards
    bsk

Page 1 of 3 123 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
  •