2011-12-16 15 views
16

रनिंग डायनेमिक्स सीआरएम 2011 रोलआउट 3. समय-समय पर लाखों ग्राहक रिकॉर्ड अपडेट करने की आवश्यकता है (डेल्टा अपडेट)। मानक अद्यतन (एक करके एक) का उपयोग कुछ हफ्तों लेता है। इसके अलावा हम सीधे डीबी को छूना नहीं चाहते हैं क्योंकि यह भविष्य में सामान तोड़ सकता है।डायनेमिक्स सीआरएम 2011 थोक अद्यतन

क्या डायनेमिक्स सीआरएम 2011 webservice/REST API में एक थोक अद्यतन विधि है जिसका हम उपयोग कर सकते हैं? (WhatWhereHow)

+0

थोक पर स्पष्ट उदाहरण बना सकते हैं या अद्यतन:

कुछ MSDN साइटों के साथ गलत हो जाता है, मैं यहाँ कि ऊपर के लिंक से एक उदाहरण पोस्टिंग कर रहा हूँ सीआरएम प्रोग्राम के लिए डेटा आयात करने के लिए कैसे दिखा रहा है नीचे दिए गए लिंक में दिए गए सीआरएम http://mscrmtutorials.blogspot.in/2014/07/bulk-insert-and-bulk-update-in-ms-crm.html –

+0

आपने क्या किया? हम किंग्सवेफ्ट –

उत्तर

11

हाँ और नहीं, अधिकांशतः नहीं। अगर कोई गलती हो तो कोई मुझे सही कर सकता है, इस मामले में मैं खुशी से अपना जवाब संपादित/हटा दूंगा, लेकिन डायनेमिक्स सीआरएम में जो कुछ भी किया गया है वह एक समय में किया जाता है। यह सेट-आधारित आवेषण/अद्यतन/हटाना को संभालने का भी प्रयास नहीं करता है। तो जब तक आप प्रत्यक्ष डीबी संचालन तक सीधे नहीं जाते, तो आपको सप्ताह लगेंगे।

webservice does allow for "bulk" inserts/deletes/updates, लेकिन मैंने उद्धरणों में "थोक" रखा क्योंकि यह सब एक असीमित प्रक्रिया स्थापित करता है जहां यह सभी प्रासंगिक डेटा संचालन करता है - एक समय में - एक। एसडीके का एक वर्ग है जो इस तरह के डेटा प्रबंधन (लिंक) को संबोधित करता है। और रिकॉर्ड्स को इस तरह अद्यतन करने के लिए, आपको पहले उस डेटा को चुनने के ऊपरी हिस्से को भुगतना होगा, जिसे आप अपडेट करना चाहते हैं, फिर डेटा युक्त एक XML फ़ाइल बनाना, और अंत में डेटा अपडेट करना (याद रखें: एक समय में एक पंक्ति)। तो यह वास्तव में आपके डेटा के माध्यम से लूप करने के लिए और अधिक कुशल होगा और प्रत्येक के लिए Update अनुरोध जारी करेगा।

(मैं नोट करेंगे कि हमारे संगठन किसी भी यादगार सीधा DB का उपयोग क्या एसडीके नहीं है संभाल करने के लिए संबंधित मुद्दों का अनुभव नहीं है, और न ही मैं अपने निजी इंटरनेट रीडिंग का सुझाव है कि दूसरों है में कुछ भी देखा है।)

संपादित करें:

iFirefly के देखें answer कुछ अन्य उत्कृष्ट तरीके इस मुद्दे के समाधान के लिए नीचे दिए गए।

1

यह सुनिश्चित नहीं है कि यह लाखों रिकॉर्ड के साथ कैसे जाएगा, लेकिन आप अपने रिकॉर्ड का चयन कर सकते हैं, फिर रिबन में संपादन बटन पर क्लिक करें। यह "एकाधिक रिकॉर्ड्स संपादित करें" संवाद लाएगा। आपके द्वारा किए गए कोई भी परिवर्तन आपके सभी रिकॉर्ड पर लागू होंगे।

+0

का उपयोग करते हैं सभी अपडेट व्यक्तिगत होते हैं और वे नियमित रूप से होते हैं। ग्राहक रिकॉर्ड के डेल्टा अपडेट = लोगों के पते, फोन नंबर आदि के परिवर्तन –

15

मुझे एहसास है कि यह पोस्ट 2 साल से अधिक पुराना है, लेकिन अगर कोई इसे पढ़ता है और मुझे इसी तरह की ज़रूरत है तो मैं इसे जोड़ सकता हूं।

पीटर मजीद का जवाब लक्ष्य पर है कि सीआरएम प्रक्रियाओं में एक समय में एक रिकॉर्ड का अनुरोध किया जाता है। कोई थोक संपादन नहीं है जो आप जिस तरीके से खोज रहे हैं वह काम करता है। मैं आपको प्रोत्साहित करता हूं कि यदि आप Microsoft समर्थन चाहते हैं/चाहते हैं तो सीधे डीबी को छूएं नहीं।

यदि आप लाखों रिकॉर्ड के आवधिक अपडेट देख रहे हैं, तो आपके पास कुछ विकल्प हैं। सीआरएम एसडीके का उपयोग करके स्क्रिप्ट का उपयोग करने या अपनी खुद की कस्टम आयात उपयोगिता या स्क्रिप्ट विकसित करने पर विचार करें।

स्क्रिप्ट संभवतः आपका सबसे अच्छा विकल्प होने जा रहा है क्योंकि यह डेटा आयात के लिए लागत प्रभावी है और आपको उसी फ़ाइल से आसानी से अपडेट और डालने की अनुमति देगा।

यदि आप अपनी खुद की .Net/SDK आधारित उपयोगिता लिखते हैं, तो मैं इसे बहुसंख्यक बनाने का सुझाव दूंगा और या तो प्रोग्राम में अपनी इनपुट फ़ाइल को मेमोरी या डिस्क में तोड़ दूंगा और प्रत्येक थ्रेड डेटा के अपने सबसेट के साथ काम करेगा - निश्चित रूप से, अगर निष्पादन के आदेश इनपुट फ़ाइल की सामग्री के अनुसार कालक्रम होना आवश्यक नहीं है। यदि आप एकाधिक थ्रेड पर इनपुट फ़ाइल को विभाजित और जीत सकते हैं, तो आप कुल निष्पादन समय को काफी कम कर सकते हैं। इसके अलावा, यदि आपकी कॉर्पोरेट नीति आपको सीआरएम सर्वरों में से किसी एक तक पहुंचने की अनुमति देती है और आप सीधे अपना सर्वर सर्वर पर रख सकते हैं और इसे वहां से निष्पादित कर सकते हैं - आप कोड चलाने और वर्कस्टेशन के बीच नेटवर्क विलंबता को समाप्त कर सकते हैं सेवाएं।

इतना ही नहीं बल्कि, अगर आयात डेटा के इस बड़ी मात्रा में किसी अन्य प्रणाली से आ रही है, तो आप एक सीआरएम प्लग-इन पर चलने के लिए लिख सकते हैं पुनः प्राप्त करें और RetrieveMultiple संदेशों सीआरएम में (घटनाओं) अपने विशिष्ट इकाई के लिए, प्रोग्राम के रूप में पुनः प्राप्त अन्य सिस्टम से वांछित डेटा (और यदि अन्य सिस्टम अनुपलब्ध है - केवल सीआरएम में कैश की गई प्रति का उपयोग करें), और वास्तविक समय में या 'अंतिम-कैश-ऑन' आधार पर सीआरएम अद्यतित रखें। यह निश्चित रूप से अधिक कोडिंग प्रयास है, लेकिन यह संभावित रूप से हर कुछ हफ्तों में एक बड़ी सिंक्रनाइज़ेशन नौकरी चलाने की आवश्यकता को समाप्त करता है।

6

मुझे एहसास है कि यह एक पुराना सवाल है लेकिन यह "सीआरएम थोक अद्यतन" पर उच्च है, इसलिए Update Rollup 12 feature ExecuteMultiple का उल्लेख यहां होना चाहिए - यह आपके मुद्दे (भारी मात्रा) के आसपास काम नहीं करेगा क्योंकि iFirefly और Peter point बाहर सीआरएम एक समय में सब कुछ करता है। यह क्या करता है आपके सभी अनुरोधों को एक ही लिफाफा में पैकेज करना है जिससे सीआरएम प्रत्येक अपडेट के निष्पादन को संभालता है और आपके रिकॉर्ड और सर्वर के बीच राउंड ट्रिप की संख्या को कम करता है यदि आप प्रत्येक रिकॉर्ड के लिए Update अनुरोध जारी करते हैं।

0

मैंने डायनेमिक्स सीआरएम 2011 के लिए एक बहुत बड़ी डेटा माइग्रेशन प्रोजेक्ट पर काम किया। हमें सप्ताहांत में लगभग 3 मिलियन रिकॉर्ड लोड करने की आवश्यकता थी। मैंने एक कंसोल एप्लिकेशन (सिंगल थ्रेड) का निर्माण समाप्त कर दिया और कई मशीनों पर कई उदाहरण चलाए। प्रत्येक कंसोल एप्लिकेशन में एक आईडी (1, 2, इत्यादि) थी और एप्लिकेशन के आईडी से मेल खाने वाले अद्वितीय SQL WHERE क्लॉज के आधार पर डेटा के सेगमेंट लोड करने के लिए ज़िम्मेदार था।

आप अपडेट के साथ एक ही काम कर सकते हैं। प्रत्येक उदाहरण रिकॉर्ड के सबसेट को अद्यतन करने के लिए क्वेरी कर सकता है और एसडीके के माध्यम से अद्यतन कर सकता है। चूंकि हमने सप्ताहांत में लाखों रिकॉर्ड लोड किए हैं, मुझे लगता है कि आप कुछ ही घंटों में लाखों अपडेट (यदि अपेक्षाकृत छोटे) कर सकते हैं।

0

गतिशीलता सीआरएम के लिए Microsoft PFE टीम नई Another CRM SDK library कि थोक निष्पादित धागा सुरक्षा सुनिश्चित करने के अनुरोध करने के लिए साथ में चलाना का इस्तेमाल करते हैं लिखा था।

आप कोशिश कर सकते हैं: समांतर निष्पादन अनुरोध मुझे यह जानने में दिलचस्पी होगी कि यह लाखों रिकॉर्डों के लिए काम करता है और स्केल करता है।

1

बल्कअपडेट एपीआई मेरे लिए अच्छा काम करता है; यह एक समय में रिकॉर्ड अपडेट करने से 10 गुना तेज है। निम्नलिखित स्निपेट है जो थोक अपडेट करता है:

public override ExecuteMultipleResponse BulkUpdate(List<Entity> entities) 
    { 
     ExecuteMultipleRequest request = new ExecuteMultipleRequest() 
     { 
      Settings = new ExecuteMultipleSettings() 
      { 
       ContinueOnError = true, 
       ReturnResponses = true 
      }, 
      Requests = new OrganizationRequestCollection() 
     }; 

     for (int i = 0; i < entities.Count; i++) 
     { 
      request.Requests.Add(new UpdateRequest() { Target = entities[i] }); 
     } 

     return (ExecuteMultipleResponse) ServiceContext.Execute(request); 
    } 
0

सीआरएम थोक डेटा अपडेट करने का कोई तरीका लागू नहीं करता है; थोक अद्यतन ऑपरेशन प्रदर्शन में सुधार करने के 3 तरीके हैं लेकिन आंतरिक रूप से वे इस तथ्य को नहीं बदल सकते हैं कि सीआरएम अपडेट एक-एक करके रिकॉर्ड करते हैं। मूल रूप से विचार कर रहे हैं:

  • समय सीआरएम सर्वर से
  • उपयोग समानांतरवाद संवाद स्थापित करने और एक ही समय
  • यकीन है कि अद्यतन प्रक्रिया किसी भी वर्कफ़्लो/प्लगइन को ट्रिगर नहीं करता बनाने में एकाधिक संचालन करने के लिए पर बर्बाद कम। नहीं तो आप इस प्रक्रिया के अंत कभी नहीं देख सकते हैं ... थोक आपरेशन प्रदर्शन में सुधार करने

3 तरीके:

  1. रोलअप 12 के बाद वहाँ एक ExecuteMultipleRequest से, जिसे आप 1000 तक भेजने की अनुमति देता है एक बार में अनुरोध इसका मतलब है कि आप सीआरएम वेब सेवा में 1000 अनुरोध भेजने से कुछ समय बचा सकते हैं, हालांकि, इन अनुरोधों को एक के बाद एक संसाधित किया जाता है।तो यदि आपका सीआरएम सर्वर अच्छी तरह से कॉन्फ़िगर किया गया है, तो संभव है कि यह विधि बहुत अधिक मदद नहीं करेगी।
  2. थोक अद्यतन करने के लिए आप OrganizationServiceContext इंस्टेंस का उपयोग कर सकते हैं। OrganizationServiceContext कार्य पैटर्न की इकाई लागू करता है ताकि आप एकाधिक अपडेट कर सकें और इन ऑपरेशन को सर्वर पर एक कॉल में प्रेषित कर सकें। ExecuteMultipleRequest की तुलना में, इसकी अनुरोध राशि पर कोई सीमा नहीं है, लेकिन यदि अपडेट के दौरान विफलता का सामना करना पड़ता है, तो यह सभी परिवर्तनों को रोलबैक करेगा।
  3. मल्टीथ्रेडिंग या मल्टीटास्क का उपयोग करें। किसी भी तरह से गति में सुधार होगा, लेकिन वे कुछ कनेक्शन विफलताओं या एसक्यूएल त्रुटियों को उत्पन्न करने की संभावना है, तो आपको कोड में कुछ पुनः प्रयास तर्क जोड़ने की आवश्यकता होगी।
1

यह एक पुराना सवाल है, लेकिन सीआरएम 201X में बड़ी मात्रा में रिकॉर्ड अपडेट करने/बनाने के लिए उपवास (लेकिन सबसे चुनौतीपूर्ण) का कोई भी उल्लेख नहीं किया गया है - अंतर्निहित आयात सुविधा का उपयोग करके, जो पूरी तरह से उपयोग करने योग्य है सीआरएम एसडीके। इसके बारे में एक आदर्श एमएसडीएन आलेख है: https://msdn.microsoft.com/en-us/library/gg328321(v=crm.5).aspx

1) Excel फ़ाइल बनाएँ डेटा आप आयात करना चाहते युक्त (बस सीआरएम 201X से कुछ डेटा निर्यात और जाँच कैसे संरचना की तरह दिखता है, याद रखें कि पहले 3 कॉलम छिपे हुए हैं)

: संक्षेप में आप के लिए है

2), बनाने के आयात मानचित्र इकाई (आपके द्वारा निर्मित फाइल)

3 उल्लेख करें) स्तंभ मैपिंग यदि आवश्यक हो तो

4) आयात और ImportFile इकाई बनाएँ उचित मैपिंग

5 प्रदान करने) का उपयोग कर डेटा पार्स ParseImportRequest

6) TransformImportRequest

7 का उपयोग कर Tranform डेटा) ImportRecordsImportRequest

इस का उपयोग कर डेटा आयात सीआरएम 2011 के लिए चरणों थे, अब 2017 में हम और अधिक संस्करण उपलब्ध है और उन दोनों के बीच मामूली मतभेद हैं। नमूना कि MSDN पर और एसडीके में उपलब्ध है की जाँच करें: https://msdn.microsoft.com/en-us/library/hh547396(v=crm.5).aspx

पाठ्यक्रम बिंदु 1 के

, सबसे कठिन हिस्सा हो जाएगा, क्योंकि आप XML या docx फ़ाइल पूरी तरह से क्या सीआरएम की उम्मीद करने के लिए इसी का निर्माण करने की है, लेकिन मैं कर रहा हूँ यह मानते हुए कि आप इसे बाहरी ऐप से कर रहे हैं, इसलिए आप कुछ महान .NET पुस्तकालयों का उपयोग कर सकते हैं जो चीजों को अधिक सरल बना देंगे।

जब मैंने समांतरता और बैच अपडेट अनुरोधों के लिए जाना है, तब भी मैंने मानक सीआरएम आयात से कुछ भी तेज नहीं देखा है। एमएस पर

using System; 
using System.ServiceModel; 
using System.Collections.Generic; 
using System.Linq; 

// These namespaces are found in the Microsoft.Xrm.Sdk.dll assembly 
// located in the SDK\bin folder of the SDK download. 
using Microsoft.Xrm.Sdk; 
using Microsoft.Xrm.Sdk.Query; 
using Microsoft.Xrm.Sdk.Client; 
using Microsoft.Xrm.Sdk.Messages; 
using Microsoft.Xrm.Sdk.Metadata; 

// These namespaces are found in the Microsoft.Crm.Sdk.Proxy.dll assembly 
// located in the SDK\bin folder of the SDK download. 
using Microsoft.Crm.Sdk.Messages; 

namespace Microsoft.Crm.Sdk.Samples 
{  
    /// <summary> 
    /// This sample shows how to define a complex mapping for importing and then use the 
    /// Microsoft Dynamics CRM 2011 API to bulk import records with that mapping. 
    /// </summary> 
    public class ImportWithCreate 
    { 
     #region Class Level Members 

     private OrganizationServiceProxy _serviceProxy; 
     private DateTime _executionDate; 

     #endregion 

     /// <summary> 
     /// This method first connects to the organization service. Afterwards, 
     /// auditing is enabled on the organization, account entity, and a couple 
     /// of attributes. 
     /// </summary> 
     /// <param name="serverConfig">Contains server connection information.</param> 
     /// <param name="promptforDelete">When True, the user will be prompted to delete all 
     /// created entities.</param> 
     public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete) 
     { 
      using (_serviceProxy = ServerConnection.GetOrganizationProxy(serverConfig)) 
      { 
       // This statement is required to enable early bound type support. 
       _serviceProxy.EnableProxyTypes(); 

       // Log the start time to ensure deletion of records created during execution. 
       _executionDate = DateTime.Today; 
       ImportRecords(); 
       DeleteRequiredRecords(promptforDelete); 
      } 
     } 

     /// <summary> 
     /// Imports records to Microsoft Dynamics CRM from the specified .csv file. 
     /// </summary> 
     public void ImportRecords() 
     { 
      // Create an import map. 
      ImportMap importMap = new ImportMap() 
      { 
       Name = "Import Map " + DateTime.Now.Ticks.ToString(), 
       Source = "Import Accounts.csv", 
       Description = "Description of data being imported", 
       EntitiesPerFile = 
        new OptionSetValue((int)ImportMapEntitiesPerFile.SingleEntityPerFile), 
       EntityState = EntityState.Created 
      }; 
      Guid importMapId = _serviceProxy.Create(importMap); 

      // Create column mappings. 

      #region Column One Mappings 
      // Create a column mapping for a 'text' type field. 
      ColumnMapping colMapping1 = new ColumnMapping() 
      { 
       // Set source properties. 
       SourceAttributeName = "src_name", 
       SourceEntityName = "Account_1", 

       // Set target properties. 
       TargetAttributeName = "name", 
       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 colMappingId1 = _serviceProxy.Create(colMapping1); 
      #endregion 

      #region Column Two Mappings 
      // Create a column mapping for a 'lookup' type field. 
      ColumnMapping colMapping2 = new ColumnMapping() 
      { 
       // Set source properties. 
       SourceAttributeName = "src_parent", 
       SourceEntityName = "Account_1", 

       // Set target properties. 
       TargetAttributeName = "parentaccountid", 
       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 colMappingId2 = _serviceProxy.Create(colMapping2); 

      // Because we created a column mapping of type lookup, we need to specify lookup details in a lookupmapping. 
      // One lookupmapping will be for the parent account, and the other for the current record. 
      // This lookupmapping is important because without it the current record 
      // cannot be used as the parent of another record. 

      // Create a lookup mapping to the parent account. 
      LookUpMapping parentLookupMapping = new LookUpMapping() 
      { 
       // Relate this mapping with its parent column mapping. 
       ColumnMappingId = 
        new EntityReference(ColumnMapping.EntityLogicalName, colMappingId2), 

       // Force this column to be processed. 
       ProcessCode = 
        new OptionSetValue((int)LookUpMappingProcessCode.Process), 

       // Set the lookup for an account entity by its name attribute. 
       LookUpEntityName = Account.EntityLogicalName, 
       LookUpAttributeName = "name", 
       LookUpSourceCode = 
        new OptionSetValue((int)LookUpMappingLookUpSourceCode.System) 
      }; 

      // Create the lookup mapping. 
      Guid parentLookupMappingId = _serviceProxy.Create(parentLookupMapping); 

      // Create a lookup on the current record's "src_name" so that this record can 
      // be used as the parent account for another record being imported. 
      // Without this lookup, no record using this account as its parent will be imported. 
      LookUpMapping currentLookUpMapping = new LookUpMapping() 
      { 
       // Relate this lookup with its parent column mapping. 
       ColumnMappingId = 
        new EntityReference(ColumnMapping.EntityLogicalName, colMappingId2), 

       // Force this column to be processed. 
       ProcessCode = 
        new OptionSetValue((int)LookUpMappingProcessCode.Process), 

       // Set the lookup for the current record by its src_name attribute. 
       LookUpAttributeName = "src_name", 
       LookUpEntityName = "Account_1", 
       LookUpSourceCode = 
        new OptionSetValue((int)LookUpMappingLookUpSourceCode.Source) 
      }; 

      // Create the lookup mapping 
      Guid currentLookupMappingId = _serviceProxy.Create(currentLookUpMapping); 
      #endregion 

      #region Column Three Mappings 
      // Create a column mapping for a 'picklist' type field 
      ColumnMapping colMapping3 = new ColumnMapping() 
      { 
       // Set source properties 
       SourceAttributeName = "src_addresstype", 
       SourceEntityName = "Account_1", 

       // Set target properties 
       TargetAttributeName = "address1_addresstypecode", 
       TargetEntityName = Account.EntityLogicalName, 

       // Relate this column mapping with its parent data map 
       ImportMapId = 
        new EntityReference(ImportMap.EntityLogicalName, importMapId), 

       // Force this column to be processed 
       ProcessCode = 
        new OptionSetValue((int)ColumnMappingProcessCode.Process) 
      }; 

      // Create the mapping 
      Guid colMappingId3 = _serviceProxy.Create(colMapping3); 

      // Because we created a column mapping of type picklist, we need to specify picklist details in a picklistMapping 
      PickListMapping pickListMapping1 = new PickListMapping() 
      { 
       SourceValue = "bill", 
       TargetValue = 1, 

       // Relate this column mapping with its column mapping data map 
       ColumnMappingId = 
        new EntityReference(ColumnMapping.EntityLogicalName, colMappingId3), 

       // Force this column to be processed 
       ProcessCode = 
        new OptionSetValue((int)PickListMappingProcessCode.Process) 
      }; 

      // Create the mapping 
      Guid picklistMappingId1 = _serviceProxy.Create(pickListMapping1); 

      // Need a picklist mapping for every address type code expected 
      PickListMapping pickListMapping2 = new PickListMapping() 
      { 
       SourceValue = "ship", 
       TargetValue = 2, 

       // Relate this column mapping with its column mapping data map 
       ColumnMappingId = 
        new EntityReference(ColumnMapping.EntityLogicalName, colMappingId3), 

       // Force this column to be processed 
       ProcessCode = 
        new OptionSetValue((int)PickListMappingProcessCode.Process) 
      }; 

      // Create the mapping 
      Guid picklistMappingId2 = _serviceProxy.Create(pickListMapping2); 
      #endregion 

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

      // Create Import File. 
      ImportFile importFile = new ImportFile() 
      { 
       Content = BulkImportHelper.ReadCsvFile("Import Accounts.csv"), // Read contents from disk. 
       Name = "Account record import", 
       IsFirstRowHeader = true, 
       ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId), 
       UseSystemMap = false, 
       Source = "Import Accounts.csv", 
       SourceEntityName = "Account_1", 
       TargetEntityName = Account.EntityLogicalName, 
       ImportId = new EntityReference(Import.EntityLogicalName, importId), 
       EnableDuplicateDetection = false, 
       FieldDelimiterCode = 
        new OptionSetValue((int)ImportFileFieldDelimiterCode.Comma), 
       DataDelimiterCode = 
        new OptionSetValue((int)ImportFileDataDelimiterCode.DoubleQuote), 
       ProcessCode = 
        new OptionSetValue((int)ImportFileProcessCode.Process) 
      }; 

      // Get the current user to set as record owner. 
      WhoAmIRequest systemUserRequest = new WhoAmIRequest(); 
      WhoAmIResponse systemUserResponse = 
       (WhoAmIResponse)_serviceProxy.Execute(systemUserRequest); 

      // Set the owner ID.     
      importFile.RecordsOwnerId = 
       new EntityReference(SystemUser.EntityLogicalName, systemUserResponse.UserId); 

      Guid importFileId = _serviceProxy.Create(importFile); 

      // Retrieve the header columns used in the import file. 
      GetHeaderColumnsImportFileRequest headerColumnsRequest = new GetHeaderColumnsImportFileRequest() 
      { 
       ImportFileId = importFileId 
      }; 
      GetHeaderColumnsImportFileResponse headerColumnsResponse = 
       (GetHeaderColumnsImportFileResponse)_serviceProxy.Execute(headerColumnsRequest); 

      // Output the header columns. 
      int columnNum = 1; 
      foreach (string headerName in headerColumnsResponse.Columns) 
      { 
       Console.WriteLine("Column[" + columnNum.ToString() + "] = " + headerName); 
       columnNum++; 
      } 

      // Parse the import file. 
      ParseImportRequest parseImportRequest = new ParseImportRequest() 
      { 
       ImportId = importId 
      }; 
      ParseImportResponse parseImportResponse = 
       (ParseImportResponse)_serviceProxy.Execute(parseImportRequest); 
      Console.WriteLine("Waiting for Parse async job to complete"); 
      BulkImportHelper.WaitForAsyncJobCompletion(_serviceProxy, parseImportResponse.AsyncOperationId); 
      BulkImportHelper.ReportErrors(_serviceProxy, importFileId); 

      // Retrieve the first two distinct values for column 1 from the parse table. 
      // NOTE: You must create the parse table first using the ParseImport message. 
      // The parse table is not accessible after ImportRecordsImportResponse is called. 
      GetDistinctValuesImportFileRequest distinctValuesRequest = new GetDistinctValuesImportFileRequest() 
      { 
       columnNumber = 1, 
       ImportFileId = importFileId, 
       pageNumber = 1, 
       recordsPerPage = 2, 
      }; 
      GetDistinctValuesImportFileResponse distinctValuesResponse = 
       (GetDistinctValuesImportFileResponse)_serviceProxy.Execute(distinctValuesRequest); 

      // Output the distinct values. In this case: (column 1, row 1) and (column 1, row 2). 
      int cellNum = 1; 
      foreach (string cellValue in distinctValuesResponse.Values) 
      { 
       Console.WriteLine("(1, " + cellNum.ToString() + "): " + cellValue); 
       Console.WriteLine(cellValue); 
       cellNum++; 
      } 

      // Retrieve data from the parse table. 
      // NOTE: You must create the parse table first using the ParseImport message. 
      // The parse table is not accessible after ImportRecordsImportResponse is called. 
      RetrieveParsedDataImportFileRequest parsedDataRequest = new RetrieveParsedDataImportFileRequest() 
      { 
       ImportFileId = importFileId, 
       PagingInfo = new PagingInfo() 
       { 
        // Specify the number of entity instances returned per page. 
        Count = 2, 
        // Specify the number of pages returned from the query. 
        PageNumber = 1, 
        // Specify a total number of entity instances returned. 
        PagingCookie = "1" 
       } 
      }; 

      RetrieveParsedDataImportFileResponse parsedDataResponse = 
       (RetrieveParsedDataImportFileResponse)_serviceProxy.Execute(parsedDataRequest); 

      // Output the first two rows retrieved. 
      int rowCount = 1; 
      foreach (string[] rows in parsedDataResponse.Values) 
      { 
       int colCount = 1; 
       foreach (string column in rows) 
       { 
        Console.WriteLine("(" + rowCount.ToString() + "," + colCount.ToString() + ") = " + column); 
        colCount++; 
       } 
       rowCount++; 
      } 

      // Transform the import 
      TransformImportRequest transformImportRequest = new TransformImportRequest() 
      { 
       ImportId = importId 
      }; 
      TransformImportResponse transformImportResponse = 
       (TransformImportResponse)_serviceProxy.Execute(transformImportRequest); 
      Console.WriteLine("Waiting for Transform async job to complete"); 
      BulkImportHelper.WaitForAsyncJobCompletion(_serviceProxy, transformImportResponse.AsyncOperationId); 
      BulkImportHelper.ReportErrors(_serviceProxy, importFileId); 

      // Upload the records. 
      ImportRecordsImportRequest importRequest = new ImportRecordsImportRequest() 
      { 
       ImportId = importId 
      }; 
      ImportRecordsImportResponse importResponse = 
       (ImportRecordsImportResponse)_serviceProxy.Execute(importRequest); 
      Console.WriteLine("Waiting for ImportRecords async job to complete"); 
      BulkImportHelper.WaitForAsyncJobCompletion(_serviceProxy, importResponse.AsyncOperationId); 
      BulkImportHelper.ReportErrors(_serviceProxy, importFileId); 
     } 

     /// <summary> 
     /// Deletes any entity records that were created for this sample. 
     /// <param name="prompt">Indicates whether to prompt the user 
     /// to delete the records created in this sample.</param> 
     /// </summary> 
     public void DeleteRequiredRecords(bool prompt) 
     { 
      bool toBeDeleted = true; 

      if (prompt) 
      { 
       // Ask the user if the created entities should be deleted. 
       Console.Write("\nDo you want these entity records deleted? (y/n) [y]: "); 
       String answer = Console.ReadLine(); 
       if (answer.StartsWith("y") || 
        answer.StartsWith("Y") || 
        answer == String.Empty) 
       { 
        toBeDeleted = true; 
       } 
       else 
       { 
        toBeDeleted = false; 
       } 
      } 

      if (toBeDeleted) 
      { 
       // Retrieve all account records created in this sample. 
       QueryExpression query = new QueryExpression() 
       { 
        EntityName = Account.EntityLogicalName, 
        Criteria = new FilterExpression() 
        { 
         Conditions = 
         { 
          new ConditionExpression("createdon", ConditionOperator.OnOrAfter, _executionDate), 
         } 
        }, 
        ColumnSet = new ColumnSet(false) 
       }; 
       var accountsCreated = _serviceProxy.RetrieveMultiple(query).Entities; 

       // Delete all records created in this sample. 
       foreach (var account in accountsCreated) 
       { 
        _serviceProxy.Delete(Account.EntityLogicalName, account.Id); 
       } 

       Console.WriteLine("Entity record(s) have been deleted."); 
      } 
     } 
     #region Main method 

     /// <summary> 
     /// Standard Main() method used by most SDK samples. 
     /// </summary> 
     /// <param name="args"></param> 
     static public void Main(string[] args) 
     { 
      try 
      { 
       // Obtain the target organization's web address and client logon 
       // credentials from the user. 
       ServerConnection serverConnect = new ServerConnection(); 
       ServerConnection.Configuration config = serverConnect.GetServerConfiguration(); 

       var app = new ImportWithCreate(); 
       app.Run(config, true); 
      } 

      catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) 
      { 
       Console.WriteLine("The application terminated with an error."); 
       Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp); 
       Console.WriteLine("Code: {0}", ex.Detail.ErrorCode); 
       Console.WriteLine("Message: {0}", ex.Detail.Message); 
       Console.WriteLine("Trace: {0}", ex.Detail.TraceText); 
       Console.WriteLine("Inner Fault: {0}", 
        null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); 
      } 
      catch (System.TimeoutException ex) 
      { 
       Console.WriteLine("The application terminated with an error."); 
       Console.WriteLine("Message: {0}", ex.Message); 
       Console.WriteLine("Stack Trace: {0}", ex.StackTrace); 
       Console.WriteLine("Inner Fault: {0}", 
        null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message); 
      } 
      catch (System.Exception ex) 
      { 
       Console.WriteLine("The application terminated with an error."); 
       Console.WriteLine(ex.Message); 

       // Display the details of the inner exception. 
       if (ex.InnerException != null) 
       { 
        Console.WriteLine(ex.InnerException.Message); 

        FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException 
         as FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>; 
        if (fe != null) 
        { 
         Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp); 
         Console.WriteLine("Code: {0}", fe.Detail.ErrorCode); 
         Console.WriteLine("Message: {0}", fe.Detail.Message); 
         Console.WriteLine("Trace: {0}", fe.Detail.TraceText); 
         Console.WriteLine("Inner Fault: {0}", 
          null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); 
        } 
       } 
      } 
      // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException, 
      // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException. 

      finally 
      { 
       Console.WriteLine("Press <Enter> to exit."); 
       Console.ReadLine(); 
      } 
     } 
     #endregion Main method 
    } 
} 
संबंधित मुद्दे