Getting InvalidValueForFileType for update using importfile API
-
vendredi 18 février 2011 20:25
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 errorThanks,
Matt
Toutes les réponses
-
lundi 2 janvier 2012 07:49I have the same problem. Can somebody help?
Edo -
mardi 3 janvier 2012 10:00ModérateurI 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- Modifié DavidJennawayMVP, Moderator mardi 3 janvier 2012 10:01
-
mardi 3 janvier 2012 10:18
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- Modifié Eduard Meciar mardi 3 janvier 2012 10:22
-
mardi 3 janvier 2012 11:14ModérateurTo 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- Modifié DavidJennawayMVP, Moderator mardi 3 janvier 2012 11:15
-
mardi 3 janvier 2012 17:24
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
-
mardi 3 janvier 2012 18:56Thanks 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.
-
mercredi 4 janvier 2012 06:04Modérateur
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- Marqué comme réponse TedMatt mardi 10 janvier 2012 17:42
-
mardi 10 janvier 2012 17:45
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
-
vendredi 15 juin 2012 21:50
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
-
mercredi 17 octobre 2012 18:47
Can anybody write c# code using MSCRM 2011 sdk to update data? Is there any example?
tks