// Create an import (data import) entity instance. import import = new import(); import.name = "Importing data"; // Distinguish between an import and an update. import.isimport = new CrmBoolean(); import.isimport.Value = true; import.modecode = new Picklist(); import.modecode.Value = ImportModeCode.Create; // Create the import (data import) entity instance. // in Microsoft Dynamics CRM Guid importId = service.Create(import); // Create a logical source file of the data being imported. importfile importFile = new importfile(); importFile.name = "Account record import."; importFile.source = "import_accounts.csv"; importFile.sourceentityname = "Account_1"; importFile.targetentityname = EntityName.account.ToString(); // Read contents from disk. importFile.content = ReadCsvFile("import_accounts.csv"); // Configure delimiters. importFile.datadelimitercode = new Picklist(); importFile.datadelimitercode.Value = ImportDataDelimiter.DoubleQuote; importFile.fielddelimitercode = new Picklist(); importFile.fielddelimitercode.Value = ImportFieldDelimiter.Comma; // Do not allow duplicate records to import. importFile.enableduplicatedetection = new CrmBoolean(); importFile.enableduplicatedetection.Value = false; // Relate the import file to the parent import (data import). importFile.importid = new Lookup(); importFile.importid.type = EntityName.import.ToString(); importFile.importid.Value = importId; // Relate this import file to the parent data map. importFile.importmapid = new Lookup(); importFile.importmapid.type = EntityName.importmap.ToString(); importFile.importmapid.Value = importMapId; // Do not use the first row during import. importFile.isfirstrowheader = new CrmBoolean(); importFile.isfirstrowheader.Value = true; // Specify to process the column. importFile.processcode = new Picklist(); importFile.processcode.Value = ImportProcessCode.Process; // Specify the current user as the record owner. WhoAmIRequest systemUserRequest = new WhoAmIRequest(); WhoAmIResponse systemUserReponse = (WhoAmIResponse)service.Execute(systemUserRequest); // Specify the owner ID. importFile.recordsownerid = new Lookup(); importFile.recordsownerid.type = EntityName.systemuser.ToString(); importFile.recordsownerid.Value = systemUserReponse.UserId; // Create the import file. Guid importFileId = service.Create(importFile); // Retrieve the header columns used in the import file. GetHeaderColumnsImportFileRequest headerColumnsRequest = new GetHeaderColumnsImportFileRequest(); headerColumnsRequest.ImportFileId = importFileId; GetHeaderColumnsImportFileResponse headerColumnsResponse = (GetHeaderColumnsImportFileResponse)service.Execute(headerColumnsRequest); // Output the header columns. int columnNum = 1; foreach(string headerName in headerColumnsResponse.Columns) { Console.WriteLine("Column[" + columnNum.ToString() + "] = " + headerName); columnNum++; }
Rechercher dans ce blog
lundi 13 août 2012
API : GetHeaderColumnsImportFileRequest
Récupère les entêtes des colonnes du fichier source; ou récupère les entêtes de colonnes générées si le fichier source ne contient pas d'entêtes de colonnes
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire