js code is working on custom module's record view but not working on create and quick create view

HI All,

Please review below js code is working on custom module's record view but not working on create and quick create view:

"({
extendsFrom: 'RecordView',

/**
* @inheritdoc
*/
initialize: function(options) {
this._super('initialize', [options]);
this.model.on("change:field_name", this.set_custom_field, this);
},
_render: function() {
alert("inside render.....");
this._super('_render');
//added call to autofill on quickcreate view of custom module  subpanel on accounts record view
this.set_custom_field();
},
set_custom_field: function(){
var account_name = this.model.get('relatinship_ida');//get account id
var _self=this;//obj of this
var account_bean = app.data.createBean('Accounts',{id: account_name});
account_bean.fetch({
success: function (data) {
if(data.attributes.avds_families_accounts_1avds_families_ida != undefined){
 alert("test data")
}

},
error: function(error) {
console.log(error);
}
});
}


})

"

Note : I don't have any create folder inside custom/module/module_name/clients/base/views/create, only I have is record folder and record.js file

Kindest Regards,

Shreya

Parents
  • What  says is correct, you can add a custom create/create.js controller that applies only to the Create action - otherwise it uses the main controller.

    However, it looks to me as if you are trying to use Javascript to pre-fill a custom field value with data from a related Account record here. The issue is that in the Create view of a new record it is unlikely that the "..._ida" relationship value will be filled in as, by definition, the record is new and doesn't actually exist until after it is saved.

    Although the relationship is not properly formed in the model at the point you are working, there should be a way to retrieve what you need. I am assuming here that you are expecting it to be related as the create action is coming from a sub-panel and therefore the Account field appears to be filled in. You probably want to put in a quick:

    console.log('This:', this);
     

    line in the set_custom_field function and inspect the model to see where this data is held. I don't have the log to hand but off the top of my head I think you are looking for the parent record value. It is likely to be there in the model somewhere.

    You then need to use that attribute in your this.model.get() call, so you are grabbing the id of the linked Account to use.

    I am fairly sure I have done this in the past when needing to work with the parent record in a controller.

    Of course, when used in the record.js the existing relationship field will probably be there but you probably want to check and see if that is empty and if it is then try to read the parent id instead.

    EDITED TO ACCOUNT FOR BRAIN FADE Slight smile

    Hopefully this helps a bit.

    Thanks,

    JH.

Reply
  • What  says is correct, you can add a custom create/create.js controller that applies only to the Create action - otherwise it uses the main controller.

    However, it looks to me as if you are trying to use Javascript to pre-fill a custom field value with data from a related Account record here. The issue is that in the Create view of a new record it is unlikely that the "..._ida" relationship value will be filled in as, by definition, the record is new and doesn't actually exist until after it is saved.

    Although the relationship is not properly formed in the model at the point you are working, there should be a way to retrieve what you need. I am assuming here that you are expecting it to be related as the create action is coming from a sub-panel and therefore the Account field appears to be filled in. You probably want to put in a quick:

    console.log('This:', this);
     

    line in the set_custom_field function and inspect the model to see where this data is held. I don't have the log to hand but off the top of my head I think you are looking for the parent record value. It is likely to be there in the model somewhere.

    You then need to use that attribute in your this.model.get() call, so you are grabbing the id of the linked Account to use.

    I am fairly sure I have done this in the past when needing to work with the parent record in a controller.

    Of course, when used in the record.js the existing relationship field will probably be there but you probably want to check and see if that is empty and if it is then try to read the parent id instead.

    EDITED TO ACCOUNT FOR BRAIN FADE Slight smile

    Hopefully this helps a bit.

    Thanks,

    JH.

Children
No Data