Question

Based on lookup value no of records must be allow

Hi Team

if the candidate selects value is Reject then it has to allow Two Attachments in the attachment file.



if he selects upload then only one attachment has to allow if he selects more than one it has to show an alert (shouldn't exceed more than one file).



for that which process I have to follow.hoping for a positive reply.

regards

manikanta

 

Like 0

Like

1 comments

Hi Manikanta,



On the page there is function asyncValidate which you can use. 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*/
	};
});

This will not cover the case when the record is deleted from detail after main record is already saved. You should use this approach to handle such situations. Please see sample below:



 

using System;
using Terrasoft.Core.DB;
using Terrasoft.Core.Entities;
using Terrasoft.Core.Entities.Events;
 
namespace ExecutorLibrary
{
    [EntityEventListener(SchemaName = "ContactFile")]
    public class UsrContactFileEventListener : BaseEntityEventListener
    {
        public override void OnDeleting(object sender, EntityBeforeEventArgs e)
        {
            base.OnDeleting(sender, e);
            var entity = (Entity)sender;
            var userConnection = entity.UserConnection;
 
            var select =
                new Select(userConnection)
                    .Column(Func.Count(Column.Const(1)))
                .From("ContactFile")
                .Where("ContactId").IsEqual(Column.Parameter(entity.GetTypedColumnValue<Guid>("ContactId"))) as Select;
 
            var count = select.ExecuteScalar<int>();
            if (count < 2)
            {
                throw new Exception("Cannot delete attachment");
            }
        }
    }
}



Regards,

Dmytro

Show all comments