Question
Adding n years to a date and assign results to a form field
00:44 May 18, 2017
Good afternoon
I'm having a problem to add n years to a date and to assign the result to a field on a form, teh code I'm using is:
completaFechasFinGarantia: function( codigoProyecto, fechaFinGarantiaEstructural, fechaFinGarantiaInstalaciones ) {
if (codigoProyecto != null){
select = Ext.create("Terrasoft.EntitySchemaQuery", {
rootSchemaName: "UsrProyecto"
});
select.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_COLUMN, "Id");
select.addColumn("UsrCodProyec");
select.addColumn("Usraniosgaranestint"); // Años Garantia Estructural
select.addColumn("Usraniosgarinstint"); // Años Garantia Instalaciones
select.addColumn("UsrFechRepMunici"); // Fecha Recepción Municipal
var filters = Ext.create("Terrasoft.FilterGroup");
// Busca por proyecto de la unidad
filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UsrCodProyec", codigoProyecto.displayValue ));
select.filters = filters;
select.execute(function(response) {
if (response.success) {
if (response.collection.getCount() > 0) {
// GET A DATE FROM TABLE
var FREcepcion = response.collection.getByIndex(0).get("UsrFechRepMunici");
// TAKE THE YEAR OF THE DATE
var anorecepcion = FREcepcion.getFullYear();
// TAKE A NUMBER OF YEARS FROM TABLE, IN THIS CASE 5 & 10 YEARS
var AnosGtiaEst = response.collection.getByIndex(0).get("Usraniosgaranestint"); // Estructural
var AnosGtiaIns = response.collection.getByIndex(0).get("Usraniosgarinstint"); // Instalaciones
// INIT VARS WITH THE SAME INITIAL DATE
var FFinGtiaEst = new Date( FREcepcion );
var FFinGtiaInst = new Date( FREcepcion );
// INCREMENT EACH DATE ON THE SPECIFIC YEAR INCREMENT (WHAT HAPPENS WITH LEAP-YEARS???)
FFinGtiaEst.setFullYear( anorecepcion + AnosGtiaEst );
FFinGtiaInst.setFullYear( anorecepcion + AnosGtiaIns );
// HERE GET AN ERROR, WHEN I TRY TO ASSIGN TO THE SCHEMA FIELDS, WHAT I'M DOING BAD?
this.set( "UsrFFinGtiEstructural", new Date(FFinGtiaEst) ); // I get an error here "Uncaught Typeerror: this.set is not a function
this.set( "UsrFFinGtiaInstalac", new Date(FFinGtiaInst) ); // I get an error here "Uncaught Typeerror: this.set is not a function
}
}
});
}
}
if (codigoProyecto != null){
select = Ext.create("Terrasoft.EntitySchemaQuery", {
rootSchemaName: "UsrProyecto"
});
select.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_COLUMN, "Id");
select.addColumn("UsrCodProyec");
select.addColumn("Usraniosgaranestint"); // Años Garantia Estructural
select.addColumn("Usraniosgarinstint"); // Años Garantia Instalaciones
select.addColumn("UsrFechRepMunici"); // Fecha Recepción Municipal
var filters = Ext.create("Terrasoft.FilterGroup");
// Busca por proyecto de la unidad
filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UsrCodProyec", codigoProyecto.displayValue ));
select.filters = filters;
select.execute(function(response) {
if (response.success) {
if (response.collection.getCount() > 0) {
// GET A DATE FROM TABLE
var FREcepcion = response.collection.getByIndex(0).get("UsrFechRepMunici");
// TAKE THE YEAR OF THE DATE
var anorecepcion = FREcepcion.getFullYear();
// TAKE A NUMBER OF YEARS FROM TABLE, IN THIS CASE 5 & 10 YEARS
var AnosGtiaEst = response.collection.getByIndex(0).get("Usraniosgaranestint"); // Estructural
var AnosGtiaIns = response.collection.getByIndex(0).get("Usraniosgarinstint"); // Instalaciones
// INIT VARS WITH THE SAME INITIAL DATE
var FFinGtiaEst = new Date( FREcepcion );
var FFinGtiaInst = new Date( FREcepcion );
// INCREMENT EACH DATE ON THE SPECIFIC YEAR INCREMENT (WHAT HAPPENS WITH LEAP-YEARS???)
FFinGtiaEst.setFullYear( anorecepcion + AnosGtiaEst );
FFinGtiaInst.setFullYear( anorecepcion + AnosGtiaIns );
// HERE GET AN ERROR, WHEN I TRY TO ASSIGN TO THE SCHEMA FIELDS, WHAT I'M DOING BAD?
this.set( "UsrFFinGtiEstructural", new Date(FFinGtiaEst) ); // I get an error here "Uncaught Typeerror: this.set is not a function
this.set( "UsrFFinGtiaInstalac", new Date(FFinGtiaInst) ); // I get an error here "Uncaught Typeerror: this.set is not a function
}
}
});
}
}
File attachments
Like
1 comments
20:08 May 18, 2017
Try to use chrome dev tools and debug the code
https://developers.google.com/web/tools/chrome-devtools/javascript/
Besides, the following code is woking properly. Please use it as an example.
attributes: { "OnUsrDATE1ChangeAttribute": { "dependencies": [ { "columns": ["UsrDATE1"], "methodName": "onUsrDATE1Changed" } ] } }, methods: { onUsrDATE1Changed: function(){ var time1 = this.get("UsrDATE1"); var time2 = new Date(time1.getTime()); time2.setFullYear(time1.getFullYear() + 1); this.set("UsrDATE2", time2); } },
Show all comments