locked
Updating existing records by importing data with the SDK and option: ImportModeCode.Update RRS feed

  • Question

  • I'm trying to import a CSV file to update existing records.  Right now I get "The File Type is Invalid" whenever this runs.


    I'm basing this off the example code in: sdk\samplecode\cs\datamanagement\dataimport

    I added a column "Account" at the beginning of the CSV: "Import Accounts.csv"

    Account,src_name,src_parent,src_addresstype
    5C1ED238-5837-E311-B443-000C2947CEBC,A. Datum Corporation2,Adventure Works,bill
    5E1ED238-5837-E311-B443-000C2947CEBC,Adventure Works2,,ship
    601ED238-5837-E311-B443-000C2947CEBC,Blue Yonder Airlines2,,bill
    621ED238-5837-E311-B443-000C2947CEBC,City Power & Light2,A. Datum Corporation,bill
    641ED238-5837-E311-B443-000C2947CEBC,"Fabrikam, Inc.2",Adventure Works,ship



    I added this column mapping:

                #region Column Zero Mappings
                // Create a column mapping for a 'text' type field.
                ColumnMapping colMapping0 = new ColumnMapping()
                {
                    // Set source properties.
                    SourceAttributeName = "Account",
                    SourceEntityName = "Account_1",
    
                    // Set target properties.
                    TargetAttributeName = "accountid",
                    TargetEntityName = Account.EntityLogicalName,
    
                    // Relate this column mapping with the data map.
                    ImportMapId =
                        new EntityReference(ImportMap.EntityLogicalName, importMapId),
    
                    // Force this column to be processed.
                    ProcessCode =
                        new OptionSetValue((int)ColumnMappingProcessCode.Process)
                };
    
                // Create the mapping.
                Guid colMappingId0 = _serviceProxy.Create(colMapping0);
                #endregion

    I also updated the code that creates the import to be .Update instead of .Create

     // Create Import
                Import import = new Import()
                {
                    // IsImport is obsolete; use ModeCode to declare Create or Update.
                    ModeCode = new OptionSetValue((int)ImportModeCode.Update),
                    Name = "Importing data"
                };

    Any thoughts on how to fix this?  Or how to submit data for updating existing records?

    I've tried using the built-in feature of exporting the "Re-importable XML file, however that doesn't help with the particular way we need to put updated data in the system.

    Thanks





    • Edited by Patrick30 Thursday, October 17, 2013 7:23 PM
    Thursday, October 17, 2013 7:17 PM

All replies

  • What line of code does the error occur on ?

    I think that you can only use an ImportMode of Update if you import an XML file, but you seem to be trying to import a CSV file


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Thursday, October 17, 2013 8:42 PM
    Moderator
  • Hi,

    I am trying to achieve the same. Create works for me, however Update doesn't works. Did you find any resolution?

    Thanks

    Vinod.

    Friday, March 21, 2014 10:55 PM