Export (0) Print
Expand All
Expand Minimize

ImportTranslationsXmlWithProgress Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Works for all deployment typesWorks online only

Import all translations from an XML file with progress logging.

The relevant classes are specified in the following table.

TypeClass
RequestImportTranslationsXmlWithProgressRequest
ResponseImportTranslationsXmlWithProgressResponse

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 ImportTranslationsXmlWithProgressRequest class as the request parameter in the Execute method.

For a list of required privileges, see ImportTranslationsXmlWithProgress Privileges.

Example

This request requires a file for import. This example exports this file from CRM and then imports it back into Microsoft Dynamics CRM.

[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;

// Used for polling our job
Guid tmpJobId = Guid.NewGuid();

// Set up the CRM Service.  
CrmService service = Microsoft.Crm.Sdk.Utility.CrmServiceUtility.GetCrmService(crmServerUrl, orgName);

service.PreAuthenticate = true;

#region Export XML
// Create the request.
ExportTranslationsXmlRequest requestExport = new ExportTranslationsXmlRequest();
                
// Execute the request.
ExportTranslationsXmlResponse responseExport = (ExportTranslationsXmlResponse)service.Execute(requestExport);

// Get the compressed data
String translationXML = responseExport.ExportXml;

#endregion

// Get the request
ImportTranslationsXmlWithProgressRequest request = new ImportTranslationsXmlWithProgressRequest();

//Assign a key to this request so we can check status
request.ImportJobId = tmpJobId;

//Assign the data to import
request.ImportXml = translationXML;

//Start the Job
service.Execute(request);

//Get the importjob used to check status 
importjob job = new importjob();

//Get a document to hold results
XmlDocument doc = new XmlDocument();

//Used to monitor progress
String progress = String.Empty;

                // Set the columns for retrieving data from the importjob.
                ColumnSet cols = new ColumnSet();
                cols.Attributes = new string[] { "data" };

//Data will be assigned once job is complete
while (progress != "Succeeded")
{
   //Delay before polling again
   System.Threading.Thread.Sleep(100);

   //Poll status of the job if the entity does not exist yet it will throw an exception
   try
   {
      // This must be done in Retreive, RetrieveMultiple is not supported for the importjob entity
      job = (importjob)service.Retrieve(EntityName.importjob.ToString(), tmpJobId, cols);

      // Data is a XML string with details about in jobs in process
      doc.LoadXml(job.data);

      //Check the status as a String
      progress = doc.GetElementsByTagName("status").Item(0).InnerText;
      
   }
   catch { }

}
[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

' Used for polling our job
Dim tmpJobId As Guid = Guid.NewGuid()

' Set up the CRM Service.  
Dim service As CrmService = Microsoft.Crm.Sdk.Utility.CrmServiceUtility.GetCrmService(crmServerUrl, orgName)

service.PreAuthenticate = True

'            #Region "Export XML"
' Create the request.
Dim requestExport As New ExportTranslationsXmlRequest()

' Execute the request.
Dim responseExport As ExportTranslationsXmlResponse = CType(service.Execute(requestExport), ExportTranslationsXmlResponse)

' Get the compressed data
Dim translationXML As String = responseExport.ExportXml

'            #End Region

' Get the request
Dim request As New ImportTranslationsXmlWithProgressRequest()

'Assign a key to this request so we can check status
request.ImportJobId = tmpJobId

'Assign the data to import
request.ImportXml = translationXML

'Start the Job
service.Execute(request)

'Get the importjob used to check status 
Dim job As New importjob()

'Get a document to hold results
Dim doc As New XmlDocument()

'Used to monitor progress
Dim progress As String = String.Empty

' Set the columns for retrieving data from the importjob.
Dim cols As New ColumnSet()
cols.Attributes = New String() {"data"}

'Data will be assigned once job is complete
Do While progress <> "Succeeded"
    'Delay before polling again
    System.Threading.Thread.Sleep(100)

    'Poll status of the job if the entity does not exist yet it will throw an exception
    Try
        ' This must be done in Retreive, RetrieveMultiple is not supported for the importjob entity
        job = CType(service.Retrieve(EntityName.importjob.ToString(), tmpJobId, cols), importjob)

        ' Data is a XML string with details about in jobs in process
        doc.LoadXml(job.data)

        'Check the status as a String
        progress = doc.GetElementsByTagName("status").Item(0).InnerText

    Catch
    End Try

Loop

See Also

Concepts

Reference


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft