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

3 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

Show all comments