Export (0) Print
Expand All
Expand Minimize

ImportXmlWithProgress Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment typesWorks online only

Import the specified set of entity customizations from an XML file with progress logging.

The relevant classes are specified in the following table.

TypeClass
RequestImportXmlWithProgressRequest
ResponseImportXmlWithProgressResponse

Remarks

The success or failure of the import operation is recorded in the import job entity.

To use this message, pass an instance of the ImportXmlWithProgressRequest class as the request parameter in the Execute method.

For a list of required privileges, see ImportXmlWithProgress Privileges.

Example

[C#]
// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
 
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Get a customization xml document by exporting one.
ExportXmlRequest exportRequest = new ExportXmlRequest();
exportRequest.ParameterXml = 
    @"<importexportxml>
        <entities>
            <entity>account</entity>   
        </entities>
        <nodes/>
        <securityroles/>
        <workflows/>
        <settings/>
    </importexportxml>";
ExportXmlResponse exportResponse = (ExportXmlResponse) service.Execute(exportRequest);
  
// Create a ImportXmlWithProgress Request.
ImportXmlWithProgressRequest request = new ImportXmlWithProgressRequest();

// Set the customization xml to import.
request.CustomizationXml = exportResponse.ExportXml;

// Set the ParameterXml which defines what cusomization to export.
request.ParameterXml =
    @"<importexportxml>
        <entities>
            <entity>account</entity>   
        </entities>
        <nodes/>
        <securityroles/>
        <workflows/>
        <settings/>
    </importexportxml>";

// Give the request a unique import Job Id.
request.ImportJobId = Guid.NewGuid();

// Execute the request. 
ImportXmlWithProgressResponse response = (ImportXmlWithProgressResponse) service.Execute(request);

// Retrieve the results of the import.
importjob job = (importjob) 
// Be aware that using AllColumns may adversely affect
// performance and cause unwanted cascading in subsequent 
// updates. A best practice is to retrieve the least amount of 
// data required.
service.Retrieve(EntityName.importjob.ToString(), request.ImportJobId, new AllColumns());
XmlDocument data = new XmlDocument();
data.LoadXml(job.data);

// See if the result of the first entity was successful
XmlNode node = data.SelectSingleNode("importexportxml/entities/entity/@result");
if (node.Value != "success")
{
    success = false;
}
[Visual Basic .NET]
' Set up the CRM service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
 
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Get a customization xml document by exporting one.
Dim exportRequest As New ExportXmlRequest()
exportRequest.ParameterXml = "<importexportxml>" & ControlChars.CrLf & "<entities>" & ControlChars.CrLf & "<entity>account</entity>" & ControlChars.CrLf & "</entities>" & ControlChars.CrLf & "<nodes></nodes>" & ControlChars.CrLf & "<securityroles></securityroles>" & ControlChars.CrLf & "<workflows></workflows>" & ControlChars.CrLf & "<settings></settings>" & ControlChars.CrLf & "</importexportxml>"
Dim exportResponse As ExportXmlResponse = CType(service.Execute(exportRequest), ExportXmlResponse)

' Build the XML string that defines what cusomization to import and publish.
Dim customizationXml As String = "<importexportxml>" & ControlChars.CrLf & "<entities>" & ControlChars.CrLf & "<entity>account</entity>" & ControlChars.CrLf & "</entities>" & ControlChars.CrLf & "<nodes></nodes>" & ControlChars.CrLf & "<securityroles></securityroles>" & ControlChars.CrLf & "<workflows></workflows>" & ControlChars.CrLf & "<settings></settings>" & ControlChars.CrLf & "</importexportxml>"

' Create a ImportXmlWithProgress request.
Dim request As New ImportXmlWithProgressRequest()

' Set the customization xml to import.
request.CustomizationXml = System.IO.File.ReadAllText("C:\Customizations.xml")

request.ParameterXml = customizationXml

' Give the request a unique import Job ID.
request.ImportJobId = Guid.NewGuid()

' Execute the request. 
Dim response As ImportXmlWithProgressResponse = CType(service.Execute(request), ImportXmlWithProgressResponse)

' Retrieve the results of the import.
' Be aware that using AllColumns may adversely affect 
' performance and cause unwanted cascading in subsequent 
' updates.  A best practice is to retrieve the least amount of 
' data required.
Dim job As importjob = CType(service.Retrieve(EntityName.importjob.ToString(), request.ImportJobId, New AllColumns()), importjob)
Dim data As New XmlDocument()
data.LoadXml(job.data)

' See if the result of the first entity was successful.
Dim node As XmlNode = data.SelectSingleNode("importexportxml/entities/entity/@result")
If node.Value <> "success" Then
   success = False
End If

If success Then
   ' Publish the imported customizations.
   Dim publishXmlRequest As New PublishXmlRequest()

   publishXmlRequest.ParameterXml = customizationXml

   ' Execute the publish request.
   service.Execute(publishXmlRequest)
End If

See Also

Concepts

Reference


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2015 Microsoft