Modify return data from related field

Hi,

I'm working on Sugar 7.5 Enterprise, i have a relation between accounts and oportunitties and i need to copy a content field from the accounts module and paste into a field in the opportunitties module, but keeping this field editable.

In SugarCE 6.5, i can modify the open_popup function in the related field from the opportunities module and add the required field:

open_popup(
  "Accounts", 
  600, 
  400, 
  "", 
  true, 
  false, 
  {"call_back_function":"set_return","form_name":"EditView","field_to_name_array":{"id":"account_id","name":"account_name", "my_account_field":"my_opportunity_field" }}, 
  "single", 
  true
);

But in Sugar 7.5 this process it's very different, i extends a record.js in the opportunities module, but i don't know how to modify the related field functionality.

Thanks for the help.

  • Hi Francesca, 

    Thanks again, the solution you provided above is working well for me now when I create a Contract from scratch.

    However when I create a Contract from the Account Screen, or from the Contract Menu, the Account Name is already populated and does not fire the OnChange event, therefore my "licneseename_c" field is not set on the Contract when they are created with this method.  (BTW we call call Contracts Agreements.)

    Do you know if this is a different Event that is fired, e.g. an OnLoad event, or is there a way of detecting where the Contract was created from, e.g. from scratch or form the Account page?  As I would like to make sure that my "licenseename_c" field is populated when I create Contracts/Agreements using these methods. 

    As always, any suggestions would be greatly appreciated. 

  • Because you are in the "Create" view clearly this is a new record, otherwise you would be in the "Record" view. This means that ever time your CreateView controller runs it does so for a brand new record.

    You could therefore run the Populate my field directly in your initialize for the first time, then repeat it if the account changes (maybe the user got the wrong account at first and wants to change it):

    ({

      extendsFrom: 'RecordView',

      initialize: function(options){

        this._super('initialize', [options]);
        this.populateMyField();
        this.model.on('change:account_id', this.populateMyField, this);
      },

        populateMyField: function(){

               ....do your thing
          
        },
    })

    The

    if(!_.isEmpty(this.model.get('account_id'))) 

    will prevent the function from running any further if there is no account selected.

    Having said that, note that you have a condition:

    if(_.isEmpty(this.model.get('licenseename_c'))){

    Which means that the function only takes effect once - the first time you set the liceseename. 

    If the user sets the account, then changes the account (maybe they made a mistake), the licesee name will NOT change to that of the newly set account. I think you should remove that if statement - though I may be missing something in your logic.

    You may also consider adding the on change event to your Record View controller in case a user wants to change the Account after the record was saved. When editing a previously saved record the controller will be the RecordView controller, not the Create controller.

    Hope this helps,

    FrancescaS