title: Dynamics 365 connection with SAP, via plugin, with errors
body: <p>I'm just a junior, and I'm taking care of a support project alone, and with many doubts. I have a plugin made, which connects the dynamics with the SAP system. every occurrence created within the dynamics, automatically has to create a protocol in SAP. Most is working, but in some cases it is not integrating. We have an integration log to track, and the message it gives is &quot;Data at the root level is invalid. Line 1, position 1.&quot; What could it be, and how could I check what's happening in real time?</p>
  <p>I appreciate any help</p>
  <hr />
  <p>SERVICE INTEGRATION SAP</p>
  <pre><code>public class IntegracaoSap
      {
          private object service;
  
          public string XmlSapRetonro { get; private set; }
          public IntegracaoSap(object provider)
          {
              this.service = provider;
          }
          public string OrganizationName { get; set; }
  
  
          private static readonly Regex _tags_ = new Regex(@&quot;&lt;[^&gt;]+?&gt;&quot;, RegexOptions.Multiline | RegexOptions.Compiled);
  
          //add characters that are should not be removed to this regex
          private static readonly Regex _notOkCharacter_ = new Regex(@&quot;[^\w;&amp;#@.:/\\?=|%!() -]&quot;, RegexOptions.Compiled);
  
  
          public string EnviarProtocolo(Ocorrencia ocorrencia, VariavelAmbiente variavelAmbiente, Email email)
          {
              if (ocorrencia == null)
              {
                  throw new Exception(&quot;Ocorrência não informada.&quot;);
              }
              var emailAssunto = &quot;&quot;;
              var response = String.Empty;
              var msgRetorno = String.Empty;
              var remetente = &quot;Remetente: &quot;;
              var assunto = &quot;Assunto: &quot;;
              var descricaoAssunto = &quot;&quot;;
              var modeAssuntoRemetente = &quot;&quot;;
  
  
              var emailCliente = string.Empty;
  
              if (email != null)
              {
  
                  if (email.De[0].Type.Equals(&quot;account&quot;, StringComparison.InvariantCultureIgnoreCase))
                  {
                      var conta = new Conta(&quot;&quot;, service).ObterPorId(email.De[0].Id);
                      emailCliente = conta.Email;
                  }
                  else if (email.De[0].Type.Equals(&quot;contact&quot;, StringComparison.InvariantCultureIgnoreCase))
                  {
                      var contato = new Contato(&quot;&quot;, service).ObterPor(email.De[0].Id);
                      emailCliente = contato.Email;
                  }
                  
               
                  emailAssunto = Regex.Replace(email.Assunto, @&quot;&lt;[^&gt;]*(&gt;|$)|&amp;nbsp;|&amp;zwnj;|&amp;raquo;|&amp;laquo;&quot;, string.Empty).Trim();
  
                  modeAssuntoRemetente = remetente + email.De[0].Name + &quot; &quot; + &quot; &quot; + emailCliente + &quot; &quot; + &quot; &quot; + &quot;\n&quot; + assunto + &quot; &quot; + &quot;\n&quot; + emailAssunto;
                  
              }
              else
              {
                  //pegar email de Contato em Ocorrencia
                  
  
                  if(ocorrencia.Cliente.Type.Equals(&quot;account&quot;,StringComparison.InvariantCultureIgnoreCase))
                  {
                      var conta = new Conta(&quot;&quot;, service).ObterPorId(ocorrencia.Cliente.Id);
                      emailCliente = conta.Email;
                  }
                  else if (ocorrencia.Cliente.Type.Equals(&quot;contact&quot;, StringComparison.InvariantCultureIgnoreCase))
                  {
                      var contato = new Contato(&quot;&quot;, service).ObterPor(ocorrencia.Cliente.Id);
                      emailCliente = contato.Email;
                  }
  
                  descricaoAssunto = Regex.Replace(ocorrencia.Descricao, @&quot;&lt;[^&gt;]*(&gt;|$)|&amp;nbsp;|&amp;zwnj;|&amp;raquo;|&amp;laquo;&quot;, string.Empty).Trim();
  
                  modeAssuntoRemetente = remetente + ocorrencia.Cliente.Name  + &quot; &quot; + &quot;\n&quot; + emailCliente + &quot; &quot; + &quot;\n&quot; + descricaoAssunto;
  
                
              }
               modeAssuntoRemetente = GetSubstring(modeAssuntoRemetente);
  
              string usuario = variavelAmbiente.ObterValorPor(&quot;b2bsac_usuario_sap&quot;).ToString();
  
              string senha = variavelAmbiente.ObterValorPor(&quot;b2bsac_senha_sap&quot;).ToString();
  
  
              string P_DESCRIPTION = string.Empty;
  
              try
              {
                  string url = variavelAmbiente.ObterValorPor(&quot;b2bsac_url_sap_ocorrencia&quot;).ToString();
                  string sapStatus = variavelAmbiente.ObterValorPor(&quot;b2bsac_sap_pstatus&quot;).ToString();
                  string processType = variavelAmbiente.ObterValorPor(&quot;b2bsac_sap_processtype&quot;).ToString();
                  string category = variavelAmbiente.ObterValorPor(&quot;b2bsac_sap_category&quot;).ToString();
                  string codeGroup = variavelAmbiente.ObterValorPor(&quot;b2bsac_sap_codegroup&quot;).ToString();
  
                  WebRequest httpWebRequest = WebRequest.Create(url);
                  httpWebRequest.ContentType = &quot;application/xml&quot;;
                  httpWebRequest.Headers[&quot;Ocp-Apim-Subscription-Key&quot;] = variavelAmbiente.ObterValorPor(&quot;b2bsac_value_sap&quot;).ToString();
                  httpWebRequest.Headers[&quot;SOAPAction&quot;] = &quot;http://sap.com/xi/WebService/soap1.1&quot;;
                  httpWebRequest.Method = &quot;POST&quot;;
  
                  httpWebRequest.Headers[&quot;Authorization&quot;] = &quot;Basic &quot; + Convert.ToBase64String(Encoding.Default.GetBytes($&quot;{usuario}:{senha}&quot;));
  
                  using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                  {
                      var xml = &quot;&lt;soapenv:Envelope xmlns:soapenv=\&quot;http://schemas.xmlsoap.org/soap/envelope/\&quot; xmlns:urn=\&quot;urn:energiasdobrasil-com-br.URA_PROTOCOLO\&quot;&gt;&quot; +
                                         &quot;   &lt;soapenv:Header/&gt;&quot; +
                                         &quot;   &lt;soapenv:Body&gt;&quot; +
                                         &quot;&lt;urn:mt_ura_protocolo&gt;&quot; +
                                           &quot;&lt;IV_BU_PARTNER&gt;&lt;/IV_BU_PARTNER&gt;&quot; +
                                           &quot;&lt;IV_PROCESS_TYPE&gt;&quot; + processType + &quot;&lt;/IV_PROCESS_TYPE&gt;&quot; +
                                           &quot;&lt;IV_DIRECTION&gt;0&lt;/IV_DIRECTION&gt;&quot; +
                                           &quot;&lt;IV_CATEGORY&gt;&quot; + category + &quot;&lt;/IV_CATEGORY&gt;&quot; +
                                           &quot;&lt;P_STATUS&gt;&quot; + sapStatus +&quot;&lt;/P_STATUS&gt;&quot; +
                                           &quot;&lt;P_DESCRIPTION&gt;PROTOCOLO E-MAIL&lt;/P_DESCRIPTION&gt;&quot; +
                                           &quot;&lt;P_CODE_GROUP&gt;&quot; + codeGroup + &quot;&lt;/P_CODE_GROUP&gt;&quot; +
                                           &quot;&lt;P_CODE&gt;PR01&lt;/P_CODE&gt;&quot; +
                                           &quot;&lt;P_FUNC_PARC&gt;ZP000010&lt;/P_FUNC_PARC&gt;&quot; +
                                           &quot;&lt;P_FUNC_PARC_RESP&gt;ZP000011&lt;/P_FUNC_PARC_RESP&gt;&quot; +
                                           &quot;&lt;P_RESP&gt;CRM_DYN&lt;/P_RESP&gt;&quot; +
                                           &quot;&lt;P_DATA&gt;&quot; +
                                              &quot;&lt;REF_GUID&gt;&lt;/REF_GUID&gt;&quot; +
                                              &quot;&lt;REF_HANDLE&gt;&lt;/REF_HANDLE&gt;&quot; +
                                              &quot;&lt;REF_KIND&gt;&lt;/REF_KIND&gt;&quot; +
                                              &quot;&lt;APPT_TYPE&gt;&lt;/APPT_TYPE&gt;&quot; +
                                              &quot;&lt;TIMESTAMP_FROM&gt;&lt;/TIMESTAMP_FROM&gt;&quot; +
                                              &quot;&lt;TIMEZONE_FROM&gt;&lt;/TIMEZONE_FROM&gt;&quot; +
                                              &quot;&lt;TIMESTAMP_TO&gt;&lt;/TIMESTAMP_TO&gt;&quot; +
                                              &quot;&lt;TIMEZONE_TO&gt;&lt;/TIMEZONE_TO&gt;&quot; +
                                              &quot;&lt;DATE_FROM&gt;&quot; + ocorrencia.CriadoEm.Value.ToString(&quot;yyyyMMdd&quot;) + &quot;&lt;/DATE_FROM&gt;&quot; +
                                              &quot;&lt;DATE_TO&gt;&quot; + ocorrencia.CriadoEm.Value.ToString(&quot;yyyyMMdd&quot;) + &quot;&lt;/DATE_TO&gt;&quot; +
                                              &quot;&lt;TIME_FROM&gt;&quot; + ocorrencia.CriadoEm.Value.ToString(&quot;hhmmss&quot;) + &quot;&lt;/TIME_FROM&gt;&quot; +
                                              &quot;&lt;TIME_TO&gt;&quot; + ocorrencia.CriadoEm.Value.ToString(&quot;hhmmss&quot;) + &quot;&lt;/TIME_TO&gt;&quot; +
                                              &quot;&lt;SHOW_LOCAL&gt;&lt;/SHOW_LOCAL&gt;&quot; +
                                              &quot;&lt;DOMINANT&gt;&lt;/DOMINANT&gt;&quot; +
                                              &quot;&lt;RULE_ID&gt;&lt;/RULE_ID&gt;&quot; +
                                              &quot;&lt;RULE_NAME&gt;&lt;/RULE_NAME&gt;&quot; +
                                              &quot;&lt;DURATION&gt;&lt;/DURATION&gt;&quot; +
                                              &quot;&lt;TIME_UNIT&gt;&lt;/TIME_UNIT&gt;&quot; +
                                              &quot;&lt;IS_DURATION&gt;&lt;/IS_DURATION&gt;&quot; +
                                              &quot;&lt;MODE&gt;&lt;/MODE&gt;&quot; +
                                           &quot;&lt;/P_DATA&gt;&quot; +
                                           &quot;&lt;P_INSTALLATION&gt;&lt;/P_INSTALLATION&gt;&quot; +
                                           &quot;&lt;P_NOTIFICATION&gt;&lt;/P_NOTIFICATION&gt;&quot; +
                                           &quot;&lt;P_SALESDOCUMENT&gt;&lt;/P_SALESDOCUMENT&gt;&quot; +
                                           &quot;&lt;P_OBJECTIVE&gt;011&lt;/P_OBJECTIVE&gt;&quot; +
                                           &quot;&lt;P_ATIVIDADE_PREC&gt;&lt;/P_ATIVIDADE_PREC&gt;&quot; +
                                           &quot;&lt;P_BUT0ID&gt;&quot; +
                                              &quot;&lt;PARTNER&gt;&lt;/PARTNER&gt;&quot; +
                                              &quot;&lt;TYPE&gt;&lt;/TYPE&gt;&quot; +
                                              &quot;&lt;IDNUMBER&gt;&lt;/IDNUMBER&gt;&quot; +
                                           &quot;&lt;/P_BUT0ID&gt;&quot; +
                                           &quot;&lt;P_LOCATION&gt;&lt;/P_LOCATION&gt;&quot; +
                                           &quot;&lt;P_ATIVIDADE_EXTERNA&gt;&quot; + ocorrencia.NumeroOcorrencia + &quot;&lt;/P_ATIVIDADE_EXTERNA&gt;&quot; +
                                           &quot;&lt;P_TELEFONE_URA&gt;&lt;/P_TELEFONE_URA&gt;&quot; +
                                           &quot;&lt;P_TEXTO&gt;&quot; +
                                              &quot;&lt;!--Zero or more repetitions:--&gt;&quot; +
                                              &quot;&lt;item&gt;&quot; +
                                                 &quot;&lt;REF_GUID&gt;&lt;/REF_GUID&gt;&quot; +
                                                 &quot;&lt;REF_HANDLE&gt;&lt;/REF_HANDLE&gt;&quot; +
                                                 &quot;&lt;REF_KIND&gt;&lt;/REF_KIND&gt;&quot; +
                                                 &quot;&lt;TDID&gt;A002&lt;/TDID&gt;&quot; +
                                                 &quot;&lt;TDSPRAS&gt;&lt;/TDSPRAS&gt;&quot; +
                                                 &quot;&lt;LANGU_ISO&gt;&lt;/LANGU_ISO&gt;&quot; +
                                                 &quot;&lt;TDSTYLE&gt;&lt;/TDSTYLE&gt;&quot; +
                                                 &quot;&lt;TDFORM&gt;&lt;/TDFORM&gt;&quot; +
                                                 &quot;&lt;TDFORMAT&gt;*&lt;/TDFORMAT&gt;&quot; +
                                                 &quot;&lt;TDLINE&gt;&quot; + modeAssuntoRemetente + &quot;&lt;/TDLINE&gt;&quot; +
                                                 &quot;&lt;MODE&gt;&lt;/MODE&gt;&quot; +
                                              &quot;&lt;/item&gt;&quot; +
                                           &quot;&lt;/P_TEXTO&gt;&quot; +
                                        &quot;&lt;/urn:mt_ura_protocolo&gt;&quot; +
                                     &quot;&lt;/soapenv:Body&gt;&quot; +
                                  &quot;&lt;/soapenv:Envelope&gt;&quot;;
                      streamWriter.Write(xml);
                  }
  
                  var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  
                  var encoding = ASCIIEncoding.UTF8;
                  using (var reader = new System.IO.StreamReader(httpResponse.GetResponseStream(), encoding))
                  {
                      response = reader.ReadToEnd();
                      msgRetorno = response;
                      this.XmlSapRetonro = response;
                  }
  
              }
              catch (Exception ex)
              {
                  msgRetorno = $&quot;Ocorreu um erro no método EnviarProtocolo: {ex.Message}&quot;;
              }
  
              return msgRetorno;
          }
          public static String UnHtml(String html)
          {
              html = HttpUtility.UrlDecode(html);
              html = HttpUtility.HtmlDecode(html);
  
              html = RemoveTag(html, &quot;&lt;!--&quot;, &quot;--&gt;&quot;);
              html = RemoveTag(html, &quot;&lt;script&quot;, &quot;&lt;/script&gt;&quot;);
              html = RemoveTag(html, &quot;&lt;style&quot;, &quot;&lt;/style&gt;&quot;);
  
              //replace matches of these regexes with space
              html = _tags_.Replace(html, &quot; &quot;);
              html = _notOkCharacter_.Replace(html, &quot; &quot;);
              html = SingleSpacedTrim(html);
  
              return html;
          }
  
          private static String RemoveTag(String html, String startTag, String endTag)
          {
              Boolean bAgain;
              do
              {
                  bAgain = false;
                  Int32 startTagPos = html.IndexOf(startTag, 0, StringComparison.CurrentCultureIgnoreCase);
                  if (startTagPos &lt; 0)
                      continue;
                  Int32 endTagPos = html.IndexOf(endTag, startTagPos + 1, StringComparison.CurrentCultureIgnoreCase);
                  if (endTagPos &lt;= startTagPos)
                      continue;
                  html = html.Remove(startTagPos, endTagPos - startTagPos + endTag.Length);
                  bAgain = true;
              } while (bAgain);
              return html;
          }
  
          private static String SingleSpacedTrim(String inString)
          {
              StringBuilder sb = new StringBuilder();
              Boolean inBlanks = false;
              foreach (Char c in inString)
              {
                  switch (c)
                  {
                      case '\r':
                      case '\n':
                      case '\t':
                      case ' ':
                          if (!inBlanks)
                          {
                              inBlanks = true;
                              sb.Append(' ');
                          }
                          continue;
                      default:
                          inBlanks = false;
                          sb.Append(c);
                          break;
                  }
              }
              return sb.ToString().Trim();
          }
  
          public static string GetSubstring(string modeAssuntoRemetente)
          {
              string valorTexto = modeAssuntoRemetente;
  
              // Pega os 132 caracteres da String   
              valorTexto = valorTexto.PadRight(132, ' ').Substring(0, 132);
             
  
  
              return valorTexto;
          }
      }
  }
  </code></pre>
  <hr />
  <p>OCURRENCE</p>
  <pre><code> public class OcorrenciaManager : IPlugin
      {
          public void Execute(IServiceProvider serviceProvider)
          {
  
              #region Contexto e Serviços
              // Obtain the execution context from the service provider.  
              IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
              // Obtain the organization service reference which you will need for  
              // web service calls. 
              IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
              IOrganizationService adminService = serviceFactory.CreateOrganizationService(null);
              IOrganizationService userService = serviceFactory.CreateOrganizationService(context.UserId);
              // Obtain the tracing service
              ITracingService trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
  
              #endregion
  
              adminService.SetDistribution(Distribution.Online);
              Entity entidadeDoContexto = SDKorePlugin.GetContextEntity(context);
  
              if (SDKorePlugin.Validate(context, SDKorePlugin.MessageName.Create, SDKorePlugin.Stage.PostOperation, SDKorePlugin.Mode.Asynchronous))
              {
  
                  Ocorrencia ocorrencia = entidadeDoContexto.Parse&lt;Ocorrencia&gt;(context.OrganizationName, context.IsExecutingOffline, adminService);
  
                  Email email = new Email(context.OrganizationName, adminService).BuscarPrimeiroEmailOcorrencia(ocorrencia.Id.Value);
                  var logIntegracao = new LogIntegracao(context.OrganizationName, adminService);
                  var variavelAmbiente = new VariavelAmbiente(context.OrganizationName, adminService);
  
                  trace.Trace(&quot;Início da integração de consulta Ocorrencia&quot;);
  
  
                  if (entidadeDoContexto.Attributes.Contains(&quot;ticketnumber&quot;) &amp;&amp; entidadeDoContexto.Attributes.Contains(&quot;description&quot;))
                  {
                      trace.Trace(&quot;Início da integração de consulta Ocorrencia&quot;);
  
                      ocorrencia.CriarXMLParaSap(ocorrencia,variavelAmbiente,email);
                  }
              }
          }
      }
  }
  </code></pre>
  <hr />
  <p>MODEL</p>
  <pre><code>    [LogicalEntity(&quot;incident&quot;)]
      public class Ocorrencia : SDKoreBase
      {
          
  
          #region Construtores
          public IOrganizationService service;
  
          public Ocorrencia(string organization)
              : base(organization)
          {
              RepositorioOcorrencia = new RepositoryOcorrencia&lt;Ocorrencia&gt;();
          }
  
          public Ocorrencia(string organization, object provider)
              : base(organization, provider)
          {
              RepositorioOcorrencia = new RepositoryOcorrencia&lt;Ocorrencia&gt;();
              RepositorioOcorrencia.SetOrganization(organization);
              this.SetProvider(provider);
          }
  
          private void SetProvider(object provider)
          {
              RepositorioOcorrencia.SetProvider(provider);
              this.Provider = provider;
          }
  
          #endregion
  
          #region Atributos
  
          private RepositoryOcorrencia&lt;Ocorrencia&gt; RepositorioOcorrencia { get; set; }
  
          [LogicalAttribute(&quot;customerid&quot;)]
          public Lookup Cliente { get; set; }
  
          [LogicalAttribute(&quot;incidentid&quot;)]
          public Guid? Id { get; set; }
  
          [LogicalAttribute(&quot;ticketnumber&quot;)]
          public string NumeroOcorrencia { get; set; }
  
          [LogicalAttribute(&quot;description&quot;)]
          public string Descricao { get; set; }
  
          [LogicalAttribute(&quot;b2bsac_integracaoSAP&quot;)]
          public Option Sac_Integracaosap { get; set; }
  
          [LogicalAttribute(&quot;emailaddress&quot;)]
          public string Email { get; set; }
  
  
          #endregion
  
          #region Métodos
  
          public Ocorrencia ObterPorNumOcorrencia(string NumeroOcorrencia)
          {
              Ocorrencia _ocorrencia = null;
  
              _ocorrencia = RepositorioOcorrencia.BuscarPorOcorrencia(NumeroOcorrencia);
              return _ocorrencia;
          }
  
          public Ocorrencia ObterPor(Guid ocorrenciaId)
          {
              return RepositorioOcorrencia.Retrieve(ocorrenciaId);
          }
  
          public Guid Criar()
          {
              return RepositorioOcorrencia.Create(this);
          }
  
          public void Atualizar()
          {
              RepositorioOcorrencia.Update(this);
          }
  
          public void CriarXMLParaSap(Ocorrencia ocorrencia, VariavelAmbiente variavelAmbiente, Email email)
  
          {
  
              string response = string.Empty;
              string MsgError = string.Empty;
  
              try
              {
                  var ocorrenciaAtualizar = new Ocorrencia(&quot;&quot;, this.Provider);
                  ocorrenciaAtualizar.Id = ocorrencia.Id;
                  ocorrenciaAtualizar.Sac_Integracaosap = new Option((int)Enumerator.IntegracaoSAP.EnviadoParaSap);
                  ocorrenciaAtualizar.Atualizar();
  
  
                  var integracaoSAP = new IntegracaoSap(this.Provider);
  
                  response = integracaoSAP.EnviarProtocolo(ocorrencia, variavelAmbiente, email);
  
                  var logIntegracao = new LogIntegracao(&quot;&quot;, this.Provider);
  
                  try
                  {
                      XmlDocument xDoc = new XmlDocument();
  
                      xDoc.LoadXml(response);
  
                      if (xDoc.SelectSingleNode(&quot;//P_MSG_RETORNO&quot;) != null)
                      {
                          if (xDoc.GetElementsByTagName(&quot;P_MSG_RETORNO&quot;).Item(0) != null)
                          {
                              MsgError = xDoc.GetElementsByTagName(&quot;P_MSG_RETORNO&quot;).Item(0).InnerText;
                          }
                      }
  
                      if ((MsgError != &quot;Atividade criada !&quot;))
                      {
  
                          ocorrenciaAtualizar.Sac_Integracaosap = new Option((int)Enumerator.IntegracaoSAP.NaoIntegradoComSap);
  
                          ocorrenciaAtualizar.Atualizar();
  
                          logIntegracao.Mensagem = MsgError;
  
                          if (!string.IsNullOrEmpty(integracaoSAP.XmlSapRetonro))
                          {
                              if (integracaoSAP.XmlSapRetonro.Length &lt;= 9000)
                              {
                                  logIntegracao.Mensagem += integracaoSAP.XmlSapRetonro;
                              }
                              else
                              {
                                  logIntegracao.Mensagem += integracaoSAP.XmlSapRetonro.Substring(0, 8999);
                              }
                          }
  
                          logIntegracao.NumeroTentativas = 1;
  
                          logIntegracao.NomeSap = &quot;&quot;;
  
                          logIntegracao.Ocorrencia = new SDKore.DomainModel.Lookup(ocorrencia.Id.Value, &quot;incident&quot;);
  
  
                          logIntegracao.Criar();
  
  
  
                      }
  
                      else
                      {
                          ocorrenciaAtualizar.Sac_Integracaosap = new Option((int)Enumerator.IntegracaoSAP.IntegradoComSap);
                          ocorrenciaAtualizar.Atualizar();
                      }
                  }
                  catch(Exception ex)
                  {
                      ocorrenciaAtualizar.Sac_Integracaosap = new Option((int)Enumerator.IntegracaoSAP.NaoIntegradoComSap);
  
                      ocorrenciaAtualizar.Atualizar();
  
                      logIntegracao.Mensagem = ex.Message;
  
                      if (!string.IsNullOrEmpty(integracaoSAP.XmlSapRetonro))
                      {
                          if (integracaoSAP.XmlSapRetonro.Length &lt;= 9000)
                          {
                              logIntegracao.Mensagem += integracaoSAP.XmlSapRetonro;
                          }
                          else
                          {
                              logIntegracao.Mensagem += integracaoSAP.XmlSapRetonro.Substring(0, 8999);
                          }
                      }
  
                      logIntegracao.NumeroTentativas = 1;
  
                      logIntegracao.NomeSap = &quot;&quot;;
  
                      logIntegracao.Ocorrencia = new SDKore.DomainModel.Lookup(ocorrencia.Id.Value, &quot;incident&quot;);
  
  
                      logIntegracao.Criar();
                  }
  
  
              }
              catch (Exception ex)
              {
                  throw new InvalidPluginExecutionException(ex.Message);
              }
  
              
          }
  
          #endregion
      }
  }
  </code></pre>