Question

Validation check during Data Import

Hi Team,

 

I need a solution where all the validations applied on the edit page code of the section are checked while data is imported into the system so as to restrict the invalid data in fields to  create new record in the section.

 

Kindly help me achieve this.

 

Best Regards,

Sarika

Like 0

Like

4 comments

Hello Sarika,

 

Could you please re-phrase your request and give me a bit more details on what business logic you are trying to achieve?

 

Kind regards,

Mira

Hello Mira,

 

The requirement is as follows: 

 

We have a validation check code for not allowing the user to enter a value greater than 5 in the DAC benefit term field on the edit page of a section with the code:

 

TermValidation:function()

            {

                var invalidMessage="";

            var term=this.get("UsrDACBenefitTerm");

                   if(term>5)

                {

                        invalidMessage =                     this.get("Resources.Strings.TermExceeds");

                this.showInformationDialog(invalidMessage);

                    }

           

                return {

                    

                    invalidMessage: invalidMessage

                };    

            }, 

    setValidationConfig :function(){

                this.callParent(arguments);

                this.addColumnValidator("UsrDACBenefitTerm", this.TermValidation);    

}

 

But this check is only administered while user is manually creating the record in that section. and during import, if the value is greater than 5 then also it is getting imported and the record with invalid value is getting generated. I want to make sure that this validation check is also performed while data is imported and created by the system and should not import the rows from the excel sheet with invalid values with greater than 5.

 

How can this be achieved?

Sarika Sharma,

This can be done pretty easily with an entity event listener class. See 

https://customerfx.com/article/adding-code-to-listen-for-entity-events-…

Basically, something like this: 

using Terrasoft.Core.Entities;
using Terrasoft.Core.Entities.Events;
 
namespace FX.EntityEventListeners
{
    [EntityEventListener(SchemaName = "UsrMyEntity")]
    public class UsrMyEntityEventListener : BaseEntityEventListener
    {
        public override void OnSaved(object sender, EntityAfterEventArgs e)
        {
            base.OnSaved(sender, e);
 
            var entity = (Entity)sender;
            if (entity.GetChangedColumnValues().Any(x => x.Name == "UsrDACBenefitTerm"))
            {
                if (entity.GetTypedColumnValue<int>("UsrDACBenefitTerm") > 5)
                    throw new Exception ("The value of UsrDACBenefitTerm cannot be greater than 5");
            }
        }
    }
}

With something like this in place, it would throw an error (and not save the record) anytime a record was attempted to be saved with a value more than 5, whether it's happening via the UI, an Excel import, or even via the OData or DataService APIs.

Ryan

Hi Ryan,

 

Thank you so much for the solution. I would definitely try this out.

 

Best regards,

Sarika

Show all comments