Skip to content

Instantly share code, notes, and snippets.

@cAstraea cAstraea/record.js
Created Apr 22, 2016

Embed
What would you like to do?
Updates field in Account module from module B. [ Module Accounts <-> Module B in a 1-n relationship ]
({ extendsFrom: 'RecordView', // extendsFrom: 'CreateView',
initialize: function(options) {
this._super('initialize', [options]);
this.model.on('sync', this.UpdateDateVisite, this);
},
UpdateDateVisite : function() {
relatedAccId = this.model.get('pca_pack_com_ag_accountsaccounts_ida');
typePack = this.model.get('v_type_pack');
pcaDatVisite = this.model.get('v_date_visite');
if ((typePack == '01') || (typePack == '05'))
{
//get the account bean
var accountBean = app.data.createBean('Accounts', {id: relAccId});
requestAccount = accountBean.fetch();
requestAccount.xhr.done(function(){
//once you have the Account information compare the visit dates
if ( moment(pcaDatVisite).isAfter(accountBean.get('v_der_date_visite_c').substr(0,10))) {
//update the date visite of account using api.call
app.api.call('update', app.api.buildURL('Accounts/'+relAccId), { "v_der_date_visite_c" : new Date(pcaDatVisite)}, {
success: _.bind(function(response) {
//response comes back from your api, maybe you want to set some value on your model or alter a response?
}, this)
});
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.