"Data not available" error message after editing custom dropdown field

I'm working in a 7.6.1.0 Sugar Professional instance. I created the dropdown field sales_person_c in the Accounts module, which will later list all the users with certain roles. To accomplish this I replaced the field vardefs with the following:

$dictionary['Account']['fields']['sales_person_c']['labelValue']='Sales Person';
$dictionary['Account']['fields']['sales_person_c']['dependency']='';
$dictionary['Account']['fields']['sales_person_c']['visibility_grid']='';
$dictionary['Account']['fields']['sales_person-c']['function']= 'populateOption';
$dictionary['Account']['fields']['sales_person_c']['functionBean']= '';
$dictionary['Account']['fields']['sales_person_c']['options']= '';
$dictionary['Account']['fields']['sales_person_c']['default']= '';
$dictionary['Account']['fields']['sales_person_c']['required']= true;
$dictionary['Account']['fields']['sales_person_c']['reportable']= true;

And put the following file in custom/Extension/application/Ext/Utils/:

<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

function populateOption(){

$GLOBALS['log']->fatal("populateOption");
$select = "SELECT u.id AS ID, CONCAT(IFNULL(u.first_name,''),' ',IFNULL(u.last_name,'')) users_full_name
FROM
(
SELECT IFNULL(users.id,'') id, IFNULL(users.first_name,'') first_name, IFNULL(users.last_name,'') last_name
FROM users
JOIN acl_roles_users rel ON rel.user_id = users.id and rel.deleted = 0
JOIN acl_roles rol ON rol.id = rel.role_id and rol.deleted = 0
WHERE ((1=1))
AND users.deleted=0 and users.status = 'Active'
AND rol.name = 'Role CRM 1'
ORDER BY first_name
) AS u
JOIN acl_roles_users rel ON rel.user_id = u.id and rel.deleted = 0
JOIN acl_roles rol ON rol.id = rel.role_id and rol.deleted = 0
WHERE rol.name = 'Salesman'
ORDER BY users_full_name";
$result = $GLOBALS['db']->query($select, TRUE, "Error: ");
$GLOBALS['log']->fatal("populateOption - Query realizada");
$list['']='';
while($row = $GLOBALS['db']->fetchByAssoc($result)){
$list[$row['ID']] = $row['users_full_name'];
$GLOBALS['log']->fatal("populateOption - ".$row['users_full_name']);
}
return $list;
}
?>

(I know the query works fine as I tested it in another script)

After a Quick Repair and Rebuild, when I try to access an Accounts record I get the following error message:

Data not available

Page does not exist or you do not have permission to access this page.

Go back to previous page.

And this error log in the browser console:

http://example.com/Sugar7/rest/v10/Accounts/enum/sales_person_c Failed to load resource: the server responded with a status of 404 (Not Found)

The populateOption function isn't being executed (there's nothing being logged).

Does anyone know where to start here?

As an addition, this is something I did in a 7.5 version before and worked just fine.

Thanks,

Rodrigo Morchio

  • Hi Rodrigo

    What is the field type of 'sales_person_c'?

    Did you see inside sugarcrm.log the log entries you defined into your function?

    Cheers

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • $dictionary['Account']['fields']['sales_person_c']['type']= 'enum';

    add the above line to your vardef file.

    Then Quick Repair and Rebuild, it should work, as it is working for me.

  • Hi André,

    It's a dropdown field and no, I don't see the entries I defined into my function. I don't know if this error is caused when this function is called or before that.

    Regards

  • Hi Hiren,

    Sorry it took so long for me to answer. I tried that with no effect, I still had the same problem.

    What I finally did was dynamically change the field options in the record.js, transforming the populateOption function into a custom endpoint. The record.js looks something like this:

    ({
    extendsFrom: 'RecordView',
    initialize: function(options) {
       this._super('initialize', [options]);
       var options;
    },
    _render: function () {
       $.ajax({
          async: false,
          beforeSend: function (request){request.setRequestHeader("OAuth-Token", SUGAR.App.api.getOAuthToken());},
          url: "rest/v10/Accounts/getsalesperson/",
          type: "GET",
          success: function(data){
              options = data;
           }
       });
       this.model.fields['sales_person_c'].options = options;
       this._super('_render');
    },
    _dispose: function() {
       this._super('_dispose');
    },
    })

    (create-actions.js also looks the same)

    And 'getsalesperson' returns an array with the following format:

    data = {"cb54e3ad-df6d-042e-c8de-565c6a2e564a": "John Doe", "7030437c-8e74-667c-9fb0-579670bb0d45": "Thomas Muller"}

    An advantage of this is I don't have to fix this everytime the field vardef is rebuilt.

    Regards,

    Rodrigo Morchio