Question

How to restrict system to save record without required detail records.

Hello Community,

 

We have a case to avoid user to save Opportunity record without product lines. In Creatio to add detail records is required saving parent record ("+" icon functionality).

 

Maybe there is some option to design creation process of Opportunity with product lines transactionally ?

 

Regards,

Marcin

Like 0

Like

5 comments
Best reply

Hello Marcin,

 

You are welcome!

 

In this case you will also need to remove this.isAddMode() check from the if clause of the asyncValidate function. As a result the asyncValidate will be only triggered in case the record is already added, opened for editing (isEditMode()) and has no product detail records.

 

Best regards,

Oscar

Hello Marcin,

 

Here is an example of the asyncValidate function that should be added to the OpportunityPageV2 schema:

asyncValidate: function(callback, scope) {
            if (this.isAddMode()||this.isEditMode()){
 			this.callParent([function(response) {
  				if (!response.success) {
   				callback.call(scope || this, response);
  				}
  			else {
   			this.checkOpportunityProduct(callback, scope || this);					
  }
 }, this]);
} else {
	this.callParent(arguments);
}
          },
checkOpportunityProduct: function (callback, scope) {
var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "OpportunityProductInterest" });
  	esq.addColumn("Opportunity", "Opportunity");
  	esq.filters.addItem(esq.createColumnFilterWithParameter(3, "Opportunity", this.get("Id")));
 
 esq.getEntityCollection(function (result) {
  if (result.success && result.collection.getCount()==0) {
   if (callback) {
	callback.call(scope, {
	 success: false,
	 message: "You cannot save, because there is no product in opportunity"
	});
   }
	}
  else {
   if (callback) {
	 callback.call(scope, {
	 success: true
	});
   }
  }
 }, this);
}

Please also note that the validator won't work for records that are being created in case the minipage is enabled in add mode for the opportunity section and also won't be triggered when copying an existing record that doesn't have records in the products detail (here):

It will be triggered in case you opened an opportunity record that doesn't contain product detail records and try saving changes:

Best regards,

Oscar

Hello Oscar,

 

Thank You for this validation, its works properly. There is a one issue: how to create child record (Opportunity Product) in add mode? 

Because to create product under opportunity i have first save opportunity (+ button on detail).

 

Regards,

Marcin

Hello Marcin,

 

You are welcome!

 

In this case you will also need to remove this.isAddMode() check from the if clause of the asyncValidate function. As a result the asyncValidate will be only triggered in case the record is already added, opened for editing (isEditMode()) and has no product detail records.

 

Best regards,

Oscar

Oleg Drobina,



The above code works fine in edit mode. What are the changes to be done for the asyncValidate to get triggered for Adding (this.isAddMode()) also and should be able to add detail records in add mode.



Currently if we use the above code we are unable to add detail records in AddMode. If we click on save after adding a record in attachment detail then the error messages pops up





 

Sivaranjani,

 

Indeed, you won't be able to go to creating a new detail record without saving the main record so this asyncValidate approach won't work here since application has to save the main record, you cannot add detail records related to an unexisting main record. What we can only do here is to allow saving records without detail records, but popup a message stating that there are no detail records and you need to create them. After saving the main record upon creation the user will open this record and won't be able to modify it unless there are records in the detail. Something like this:

save: function() {
				this.callParent(arguments);
				if (this.isAddMode()) {
					Terrasoft.showInformation("Don't forget to add products!");
				}
			},
 
			asyncValidate: function(callback, scope) {
				if (this.isEditMode()){
					this.callParent([function(response) {
						if (!response.success) {
							callback.call(scope || this, response);
						}
						else {
							this.checkOpportunityProduct(callback, scope || this);					
						}
					}, this]);
				} else {
					this.callParent(arguments);
				}
			},
 
			checkOpportunityProduct: function (callback, scope) {
				var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "OpportunityProductInterest" });
				esq.addColumn("Opportunity", "Opportunity");
				esq.filters.addItem(esq.createColumnFilterWithParameter(3, "Opportunity", this.get("Id")));
				esq.getEntityCollection(function (result) {
					if (result.success && result.collection.getCount()==0) {
						if (callback) {
							callback.call(scope, {
								success: false,
								message: "You cannot save, because there is no product in opportunity"
							});
						}
					}
					else {
						if (callback) {
							callback.call(scope, {
								success: true
							});
						}
					}
				}, this);
			}

  

Show all comments