1

I have made a custom dropdown field in leads module. Its a dynamically fetching users from users table from the leads module as key => value pair.

The field works fine but when in the edit mode (create a new lead)...the value is not getting stored and instead the key is getting stored not value..

I mean like instead of 'James Bond' the id is getting stored ..which is like '7896877'

Now the funny thing is that in the detail view in sugarcrm (leads module) the name is displayed properly as i wanted it to work. ONly in the list view it displays the ID and also in the database its getting stored as KEY i.e the hash ID.

This is the function:

function getUSERS($bean) {
    $resultArray = Array();

    $query = "select id,(first_name + ' ' + last_name) AS Name from    dbo.users      ORDER BY first_name ASC";
    $resultArray [''] = '';
    $result = $bean->db->query($query);
    while ($row = $bean->db->fetchByAssoc($result)) {
        $resultArray[$row['id']] = $row['Name'];
    }

    return $resultArray;
}
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
user3054077
  • 49
  • 2
  • 7

1 Answers1

0

Dropdowns in Sugar work as key/value pairing, the key is what is stored in the database and Sugar does the appropriate lookup to display the value. Except the list view seems to work differently for dynamic dropdowns.

Instead of building your array as $resultArray[$row['id'] ]= $row['Name'] you could use the username -$resultArray[$row['username'] ]= $row['Name']as usernames have to be unique but will be more meaningful to your users in the list view.

However, is there any reason you're not using a relate field to the Users module? That should solve all your problems without any coding.

MartinTawse
  • 321
  • 2
  • 10
  • Thanks Martin but the business requirement was that u use dropdown...so cannot use relate field. Anyways but i have solved the problem. What i have done is i am using logic hook and created a function to update the field accordingly... – user3054077 Apr 28 '14 at 21:12