How to Validate Duplicate Data imported from Excel RRS feed

  • Question

  • Hi,

    Was able to import data successfully from Excel using Excel Importer.  Wanted to validate the data coming from Excel.

    Scenario : I got a table with 3 rows.

    Batch_ID   Batch_Code  Batch_Description

    1. B1              B1                   First Batch

    2. B2             B2                    2nd Batch

    3. B3             B3                     3rd Batch.

     In the case of the screen input, i am able to perform validation using the  <entity>_validate method in the table.

    When importing from Excel, there is a duplicate record as (B2, B2, '2nd Batch'). Able to insert into the table without any validation check. How to validate data that is coming from Excel.




    Thursday, March 14, 2013 6:03 AM

All replies

  • If you add the required validation (ie checking for duplicates) in the entity's Validate method, it will be fired whether the data comes from a screen or from the Excel Importer extension.

    LightSwitch should then indicate that there are "validation errors" when you try to save the imported records.

    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
    By doing this you'll help others to find answers faster.

    Thursday, March 14, 2013 10:47 AM
  • Yes, Have written the code to validate.

    partial void BATCH_CODE_Validate(EntityValidationResultsBuilder results)
                var bCode = this.DataWorkspace.ApplicationData.OMD_BATCH_TABLE.Where(c => c.BATCH_CODE == this.BATCH_CODE).FirstOrDefault();
                if (bCode != null)
                    results.AddPropertyError("Duplicate Batch Code. Please Enter Unique Batch Code");

    It works fine with the screen input, but not with the import of Excel. When Import button is clicked, SelectfileDialog box opens and choose of a excel, list of columns are mapped. When click of the Ok button, all the records from the excel is inserted in the Grid of Table screen. Then when clicked Save, the records are saved. Don't see any validation happening. 

    Had tried to write a method <Screen>_Saving() - which would validate a query something like distinct of rows for batch_code. If not disctinct values, throw a error message. (Not sure of how to implement)

    Please share your thoughts on this.



    Thursday, March 14, 2013 10:54 PM