How to set a value of dropdown based on parent dropdown.

Hello,

I want to set value in dropdown from parent dropdown. Based on selection of company I need to show group lists from database. If company name is changed then group name should be get from currently selected company. 

SugarCRM Version : 7.9.0.0

Below is my code

({
extendsFrom: 'CreateView',
initialize: function (options) {
this.model.on("change:tally_company_name",this.selectgroupbaseoncompany, this);
this._super('initialize',[options]);
this.on('render', this.selectgroupbaseoncompany, this);
},

selectgroupbaseoncompany:function()
{
var tally_company_name = this.model.get('tally_company_name');
var self = this;
$.ajax(
{
url: 'rest/v10/TallyConnector/GetTallyGroupNameByCompanyName/'+tally_company_name,
type: 'POST',
success: function(get_body)
{
var dd_values = [];
_.each(get_body, function(value, key) {
console.log(key, value);
dd_values[key] = value;
});
this.model.fields['tally_group'].options = dd_values; // set data to list element
this.render();
}
});

},
})

But it show me error Uncaught TypeError: Cannot read property 'fields' of undefined at

Parents
  • If Company and those data to be fetched from database are related somehow (perhaps foreign key account_id) so you can setup an initial_filter. It is much easier to accomplish and do not require js controller.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • I have a table group_list, which has two fields. 

    1) company_name
    2) group_name

    company_namegroup_name
    DreamertechsSundry Debtors
    DreamertechsSuspense A/c
    DreamertechsUnsecured Loans
    Edgeline Kenya Steel LimitedBank Accounts
    Edgeline Kenya Steel LimitedBank OD A/c
    Edgeline Kenya Steel LimitedBranch / Divisions
    Edgeline Kenya Steel LimitedCapital Account
    Edgeline Kenya Steel LimitedCash-in-hand


    values are stored like above. Based on company name. All the group list will be selected.

    var def for tally_group is as below

    <?php

    $dictionary['Account']['fields']['tally_group']['name'] = 'tally_group';
    $dictionary['Account']['fields']['tally_group']['vname'] = 'LBL_TALLY_GROUP';
    $dictionary['Account']['fields']['tally_group']['type'] = 'enum';
    $dictionary['Account']['fields']['tally_group']['function'] = 'getTallyGroupName';

Reply
  • I have a table group_list, which has two fields. 

    1) company_name
    2) group_name

    company_namegroup_name
    DreamertechsSundry Debtors
    DreamertechsSuspense A/c
    DreamertechsUnsecured Loans
    Edgeline Kenya Steel LimitedBank Accounts
    Edgeline Kenya Steel LimitedBank OD A/c
    Edgeline Kenya Steel LimitedBranch / Divisions
    Edgeline Kenya Steel LimitedCapital Account
    Edgeline Kenya Steel LimitedCash-in-hand


    values are stored like above. Based on company name. All the group list will be selected.

    var def for tally_group is as below

    <?php

    $dictionary['Account']['fields']['tally_group']['name'] = 'tally_group';
    $dictionary['Account']['fields']['tally_group']['vname'] = 'LBL_TALLY_GROUP';
    $dictionary['Account']['fields']['tally_group']['type'] = 'enum';
    $dictionary['Account']['fields']['tally_group']['function'] = 'getTallyGroupName';

Children