locked
Custom Import Application creating Import System Job - Records are not imported & Job Status Failed RRS feed

  • Question

  • Hi,

    I have created a console application intended to read a XML data file and create records in CRM.

    1. I have defined a Data map in crm and retrieving it in the code and passing it.

    2. The code executes without any error.

    3. Creates a Import Job record in CRM

    4. Initially it shows status parsing and also shows total record count.

    5. Next it shows Failed status. But when I opened Import record, it didn't have any failures & the System jobs were successful as well. 

    I am not sure what am I missing here. Please have a look at the code and let me know what is the issue in it.

    Thanks in advance,

    Danny

    static void Main(string[] args)
            {
                // Load the xml spreasheet file from your local drive using XmlDocument class
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(@"C:\Customer.xml");
    
                IOrganizationService service = createService();
    
                // Create the Import
                Entity import = new Entity("import");
                import.Attributes.Add("modecode", new OptionSetValue(0));
                import.Attributes.Add("name", "CustomEntityDataImport");
                import.Attributes.Add("sendnotification", false);
                Guid importId = service.Create(import);
    
                // Get the Guid of the DataMap by using the datamap name
                QueryExpression custDataMap = new QueryExpression("importmap");
                ConditionExpression cond1 = new ConditionExpression("name", ConditionOperator.Equal, "CustomerDataMap");
                FilterExpression filter1 = new FilterExpression(LogicalOperator.And);
                filter1.AddCondition(cond1);
                custDataMap.Criteria.AddFilter(filter1);
                custDataMap.ColumnSet = new ColumnSet(new string[] { "name" });
                EntityCollection custDataMaps = service.RetrieveMultiple(custDataMap);
                Entity dataMap = new Entity("importmap");
                if (custDataMaps.Entities.Count > 0)
                {
                    dataMap = custDataMaps[0];           
                
                    Entity importFile = new Entity("importfile");
                    importFile.Attributes.Add("content", xmldoc.InnerXml);
                    importFile.Attributes.Add("name", "CustomEntityDataImport");
                    importFile.Attributes.Add("filetypecode", new OptionSetValue(1));
                    importFile.Attributes.Add("isfirstrowheader", true);
                    importFile.Attributes.Add("source", Path.GetFileName("CustomEntityDataImport.xml"));
                    importFile.Attributes.Add("sourceentityname", "xrm_customer");
                    importFile.Attributes.Add("targetentityname", "xrm_customer");
                    importFile.Attributes.Add("importmapid", new EntityReference("import", dataMap.Id));
                    importFile.Attributes.Add("importid", new EntityReference("import", importId));
                    importFile.Attributes.Add("size", importFile["content"].ToString().Length.ToString());
                    importFile.Attributes.Add("processcode", new OptionSetValue(1));
                    importFile.Attributes.Add("usesystemmap", false);
                    importFile.Attributes.Add("enableduplicatedetection", true);
                    service.Create(importFile);
    
                    ParseImportRequest parseRequest = new ParseImportRequest();
                    parseRequest.ImportId = importId;
                    service.Execute(parseRequest);
                    TransformImportRequest transRequest = new TransformImportRequest();
                    transRequest.ImportId = importId;
                    TransformImportResponse transResponse = (TransformImportResponse)service.Execute(transRequest);
                    ImportRecordsImportRequest request = new ImportRecordsImportRequest();
                    request.ImportId = importId;
                    ImportRecordsImportResponse response = (ImportRecordsImportResponse)service.Execute(request);
                }
            }


    Danny



    • Edited by Danny_Archer Wednesday, September 25, 2013 1:12 PM
    Wednesday, September 25, 2013 1:01 PM

Answers

  • Found the resolution here 

    In the code these values were different than the mapping file entries which were TargetEntityName="xrm_customer" SourceEntityName="Customer" 



    Danny

    • Marked as answer by Danny_Archer Thursday, September 26, 2013 9:58 AM
    Thursday, September 26, 2013 9:58 AM