Question

Validation on field using esq

How will I applied validation on two fields and restrict to saving records using esq

Like 0

Like

1 comments

Hi Bhumika,



You should use asyncValidate function on the page. See example below:



 

define("ContactPageV2", ["ConfigurationConstants", "css!OpportunityCommonCSS"], function(ConfigurationConstants) {
	return {
		entitySchemaName: "Contact",
		attributes: {},
		modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
		methods: {
			asyncValidate: function(callback, scope) {
				this.callParent([function(result) {
					if (!this.validateResponse(result)) {
						return;
					}
					this.Terrasoft.chain(
						function(next) {
							var type = this.get("Type") && this.get("Type").value;
							if (this.changedValues.hasOwnProperty("Type") &&
									type === ConfigurationConstants.ContactType.Employee) {
								this.validateAttachments(function(response) {
									if (this.validateResponse(response)) {
										next();
									}
								}, this);
							} else {
								next();
							}
						},
						function(next) {
							callback.call(scope, result);
							next();
						},
						this
					);
				}, this]);
			},
			validateAttachments: function(callback, scope) {
				var result = {
					success: true
				};
 
				var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", {
					rootSchemaName: "ContactFile"
				});
				esq.addAggregationSchemaColumn("Id",
					this.Terrasoft.AggregationType.COUNT, "AttachedFiles");
				esq.filters.addItem(esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,
					"Contact", this.get("Id")));
				esq.getEntityCollection(function(response) {
					if (response.success) {
						if (response.collection.getItems()[0].get("AttachedFiles") < 2) {
							result.message = this.get("Resources.Strings.InvalidAttachments");
							result.success = false;
						}
					}
					callback.call(scope || this, result);
				}, this);
			}
		},
		dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
		diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/
	};
});

Regards,

Dmytro

Show all comments