locked
Getting InvalidValueForFileType for update using importfile API RRS feed

  • Question

  • I am using sdk to import data into Dynamics CRM online. I used import with ImportModeCode set to Create and imported all the records just fine. The problem starts when I use the same code to update data and change the ImportModeCode of import to update. I start getting InvalidValueForFileType  (-2147220664) when I send the request to create the importfile for the import. Any suggestions?

                import import = new import();
                import.isimport = new CrmBoolean(true);
                import.name = "Insert/Update";
                import.modecode = new Picklist(ImportModeCode.Create); // works fine, but when I change it to Import ImportModeCode.Update, I start getting the error
                Guid importId = CrmService.Create(import);

                importfile importFile = new importfile();

                // Set file properties
                importFile.name = "Import File";
                importFile.source = dataFilePath; // this is a valid csv file with .csv extension
                importFile.sourceentityname = EntityName.account.ToString() + "_1";
                importFile.targetentityname = EntityName.account.ToString();

                importFile.isfirstrowheader = new CrmBoolean(true);


                importFile.enableduplicatedetection = new CrmBoolean(false);

                importFile.datadelimitercode = new Picklist(ImportDataDelimiter.DoubleQuote);
                importFile.fielddelimitercode = new Picklist(ImportFieldDelimiter.Comma);

                importFile.importmapid = new Lookup(EntityName.importmap.ToString(), importMapId);
                importFile.importid = new Lookup(EntityName.import.ToString(), this.Import);

                importFile.processcode = new Picklist();
                importFile.processcode.Value = ImportProcessCode.Process;

                importFile.content = File.ReadAllText(dataFilePath);
                // Create the import file
                Guid importFileId = CrmService.Create(importFile); // this is where I am getting error

    Thanks,

    Matt

    Friday, February 18, 2011 8:25 PM

Answers

  • The SDK documentation states:

    To update, use the data export and import capabilities of the Microsoft Dynamics CRM Web application. Use the Export to Excel feature that is available in the Web application to export data into a XML Spreadsheet 2003 (.xml) source file. This is the only valid source file type in the Update mode

    So, if the import is to update records the FileTypeCode must be set to 1, which is not the default


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
    • Marked as answer by TedMatt Tuesday, January 10, 2012 5:42 PM
    Wednesday, January 4, 2012 6:04 AM
    Moderator

All replies

  • I have the same problem. Can somebody help?
    Edo
    Monday, January 2, 2012 7:49 AM
  • I can't see the importFile.FileTypeCode property set in the code above, which I think you need. See http://msdn.microsoft.com/en-us/library/gg309712.aspx for the possible values 
    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Tuesday, January 3, 2012 10:00 AM
    Moderator
  • It's not in importFile, but in import. http://msdn.microsoft.com/en-us/library/gg328294.aspx

     

    Microsoft do not recommend updating records using data import programmatically. But I guest, it's possible. Question is, how? http://msdn.microsoft.com/en-us/library/gg334535.aspx


    Edo
    Tuesday, January 3, 2012 10:18 AM
  • To clarify, FileTypeCode is on the ImportFile entity, not the Import entity. For ModeCode (which is on the Import entity) = Update, then FileTypeCode will have to be 1 ('XML Spreadsheet 2003')
    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Tuesday, January 3, 2012 11:14 AM
    Moderator
  • David,

     

    I had the same issue and I have the FileTypeCode set to 0, that is a CSV file. I keep getting the invalidValueForFileType error. Does it mean that the file type has to be XML and CSV is not supported ?

     

    Thanks

    Tuesday, January 3, 2012 5:24 PM
  • Thanks for the replies. I had given up after trying out all the different combinations. FileTypeCode enum's default value is a csv. Please let me know if anybody has any luck.
    Tuesday, January 3, 2012 6:56 PM
  • The SDK documentation states:

    To update, use the data export and import capabilities of the Microsoft Dynamics CRM Web application. Use the Export to Excel feature that is available in the Web application to export data into a XML Spreadsheet 2003 (.xml) source file. This is the only valid source file type in the Update mode

    So, if the import is to update records the FileTypeCode must be set to 1, which is not the default


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
    • Marked as answer by TedMatt Tuesday, January 10, 2012 5:42 PM
    Wednesday, January 4, 2012 6:04 AM
    Moderator
  • I tried XML spreadsheet and it seems to work. This is a bizarre format to support, when the csv option is already available.

    David, thanks for a help!

     

    Matt

    Tuesday, January 10, 2012 5:45 PM
  • I created the XML spreadsheet, but it creates some additional (Do Not Modify) values that I'm not sure what to do with.  For example, are they set to Ignore, Internal, etc.  I'm also not sure how to specify the primary key.  Do you have a map sample that you defined that works for updating data so I can try and apply the same concepts to my maps?  Thanks a lot

    Friday, June 15, 2012 9:50 PM
  • Can anybody write c# code using MSCRM 2011 sdk to update data? Is there any example?

    tks

    Wednesday, October 17, 2012 6:47 PM
  • Hi Matt,

    Can you email me sample code for update. I am trying but with no luck.

    Thanks,

    Vinod.

    Friday, March 21, 2014 11:05 PM