Perform verification whenever a user adds or modifies a daily tour offer as follows: if the total number of active daily tours exceeds the system setting value , saving a record should not be permitted. Instead, a user should receive a message informing that no more than “N” daily tours can be active at a time. “N” is the system setting value.
Here is my code :
asyncValidate: function(callback, scope) { this.callParent([ function(response) { if (!this.validateResponse(response)) { return; } this.validateTravelOfferTour(function(response) { if (!this.validateResponse(response)) { return; } callback.call(scope, response); }, this); }, this ]); }, validateTravelOfferTour: function(callback, scope) { // Fetch the Maximum Number Of Daily Periodical Editions System Setting var mySetting = Terrasoft.SysSettings.cachedSettings.Usr_Max_Number_Activity_Tours; var FrequencyObject=this.get("UsrTravelOfferFrequency"); if(!FrequencyObject){ if(callback){ callback.call(scope,{ success:true }); } return; } var FrequencyId=FrequencyObject.value; //create query var esq=this.Ext.create("Terrasoft.EntitySchemaQuery",{ rootSchemaName:"UsrTravelOffers" }); //esq.addAggregationSchemaColumn("UsrActive",Terrasoft.AggregationType.) var ActivityFilter = esq.createColumnFilterWithParameter(0, "UsrActive", "1"); var frequencyFilter=esq.createColumnFilterWithParameter(0,"UsrTravelOfferFrequency",FrequencyId); esq.filters.addItem(frequencyFilter); esq.filters.addItem(ActivityFilter); // Aggregation to get the Count of resulting Query esq.addAggregationSchemaColumn("UsrActive", Terrasoft.AggregationType.COUNT, "ActiveOffers"); //run query // Get the entire esq result colelction esq.getEntityCollection(function(result) { if (result.success && result.collection) { // Store the Count of Filtered Records to a variabble var items = result.collection.getItems(); if(items.length>0){ esqresult=items[0].get("ActiveOffers"); } if(esqresult==mySetting){ if(callback){ callback.call(this,{ success:false, message:"no more than 3 daily tours can be active at a time." }); } }else if(callback){ callback.call(scope,{ success:true }); } } },this); },
and this is the error :
{"responseStatus":{"ErrorCode":"InvalidObjectStateException","Message":"Condition with type \"Between\" must contain two expressions in the left part.","Errors":[]},"rowsAffected":-1,"nextPrcElReady":false,"success":false}
Like
Since it's more of a question about the ESQ, the first parameter for createColumnFilterWithParameter is a value from Terrasoft.ComparisonType. You have a 0 (zero) there, which means a BETWEEN. Instead it should be 3, which is EQUAL. It's better to use the value Terrasoft.ComparisonType.EQUAL so the code is easier to read.
var ActivityFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UsrActive", "1"); var frequencyFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,"UsrTravelOfferFrequency", FrequencyId);
Ryan
Hello,
Thanks for your question. Please note that posting certification questions is not encouraged on our platform.
Thank you for understanding!
Best regards,
Anastasiia
Since it's more of a question about the ESQ, the first parameter for createColumnFilterWithParameter is a value from Terrasoft.ComparisonType. You have a 0 (zero) there, which means a BETWEEN. Instead it should be 3, which is EQUAL. It's better to use the value Terrasoft.ComparisonType.EQUAL so the code is easier to read.
var ActivityFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UsrActive", "1"); var frequencyFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,"UsrTravelOfferFrequency", FrequencyId);
Ryan