Preview:
    <script runat="server">
        Platform.Response.SetResponseHeader("Content-Security-Policy", "default-src 'self'; img-src 'self' https://image.digital.endesaclientes.com https://image.dev.notificaciones.endesaclientes.com;style-src 'self' https://cloud.dev.notificaciones.endesaclientes.com/Captacion-email-ML-CSS https://cloud.dev.notificaciones.endesaclientes.com/Captacion-email-CSS-Fuente https://cloud.digital.endesaclientes.com/css-bootstrap-ml; font-src 'self' https://cloud.dev.notificaciones.endesaclientes.com/Captacion-email-CSS-Fuente data:; script-src 'self' 'unsafe-inline' https://code.jquery.com/jquery-3.7.1.min.js https://cloud.dev.notificaciones.endesaclientes.com/Captacion-email-ML-JS https://cloud.dev.notificaciones.endesaclientes.com/Captacion-email-JS-errores-es;")
        Platform.Response.SetResponseHeader("X-Frame-Options", "DENY");
        Platform.Response.SetResponseHeader("X-Content-Type-Options", "nosniff");
        Platform.Response.SetResponseHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload");
        Platform.Response.SetResponseHeader("Referrer-Policy", "no-referrer");
        Platform.Response.SetResponseHeader("Permissions-Policy", "geolocation=(), microphone=()");
  </script>

<script runat="server">

  Platform.Load("Core", "1.1.1")
  try {
    var data = Request.GetFormField("data");

    JSON = Platform.Function.ParseJSON(data);

    Email = JSON.Email;
    nDocumento = JSON.Documento;
    AccountId = JSON.AccountId;
    ContactId = JSON.ContactId;  
    otrasComunicaciones = JSON.otrasComunicaciones;
    proteccionDatos = JSON.proteccionDatos;
    today = new Date();
 
    
    Variable.SetValue("@accountIdAmpscript", AccountId);
    Variable.SetValue("@contactIdAmpscript", ContactId);
    Variable.SetValue("@emailAmpscript", Email);

</script>

%%[

SET @retrieveAcc = RetrieveSalesforceObjects('Account', 'Id, Identifier_Type__c, NIF_CIF_Customer_NIE__c', 'Id', '=', @accountIdAmpscript)
SET @accountId = Field(Row(@retrieveAcc, 1), 'Id')
SET @tipoDocumento = Field(Row(@retrieveAcc, 1), 'Identifier_Type__c')
SET @numDocumento = Field(Row(@retrieveAcc, 1), 'NIF_CIF_Customer_NIE__c')
SET @responseAcc = Concat(@accountId, ',', @tipoDocumento, ',', @numDocumento)

SET @retrieveCont = RetrieveSalesforceObjects('Contact', 'Id, NIF_CIF_Customer_NIE__c', 'Id', '=', @contactIdAmpscript)
SET @contactId = Field(Row(@retrieveCont, 1), 'Id')
SET @contactDocumento = Field(Row(@retrieveCont, 1), 'NIF_CIF_Customer_NIE__c')
SET @responseCont = Concat(@contactId, ',', @contactDocumento)

]%%

<script runat="server">

    var responseAcc = Variable.GetValue("@responseAcc");
    var responseCont = Variable.GetValue("@responseCont");

    if (responseAcc && responseCont) {
      var responseAccRowData = responseAcc.split(',');
      var accountData = {
        id: responseAccRowData[0],
        tipoDocumento: responseAccRowData[1],
        numDocumento: responseAccRowData[2]
      };
      var responseContRowData = responseCont.split(',');
      var contactData = {
        id: responseContRowData[0],
        contactDocumento: responseContRowData[1]
      };      


      if (accountData.id == AccountId && accountData.numDocumento == nDocumento && contactData.id == ContactId && contactData.contactDocumento == nDocumento) {

</script>

%%[

SET @updateEmailAcc = UpdateSingleSalesforceObject('Account', @accountIdAmpscript, 'Email_con__c', @emailAmpscript, 'No_Email_flg__c', 'false')
SET @updateEmailCon = UpdateSingleSalesforceObject('Contact', @contactIdAmpscript, 'Email', @emailAmpscript, 'Validate_email__c', 'false', 'No_Email_flg__c', 'false')
SET @updateResponse = Concat(@updateEmailAcc, ',', @updateEmailCon)

]%%

<script runat="server">

          var updateResponse = Variable.GetValue("@updateResponse")


          var updateResponseRowData = updateResponse.split(',');
          var updateResponseData = {
            AccEmail: updateResponseRowData[0],
            ContEmail: updateResponseRowData[1]
          };


          if (updateResponseData.AccEmail == 1 && updateResponseData.ContEmail == 1) {

</script>

%%[

SET @createCase = CreateSalesforceObject('Case', 4, 'Subject', 'Modificación de cliente', 'AccountId', @accountIdAmpscript, 'RecordTypeId', '0121r000000Vl8IAAS', 'Status', 'New')


]%%

<script runat="server">

             var createCase = Variable.GetValue("@createCase") //Devuelve el ID

             if (createCase) {

</script>

%%[

SET @createTask = CreateSalesforceObject('Task', 6, 'RecordTypeId', '0121r000000Vl90AAC', 'Type', 'Action', 'Subject','Modificación de cliente', 'Status', 'Completed', 'WhatId', @createCase, 'FII_ACT_LKP_RelatedClient__c', @accountIdAmpscript)


]%%

<script runat="server">

            var createTask = Variable.GetValue("@createTask") //Devuelve el ID

            if (createTask) {

              if (otrasComunicaciones) {


</script>

%%[

SET @retrieveIndividual = RetrieveSalesforceObjects('Individual', 'Id', 'Contact__c', '=', @contactIdAmpscript)

IF RowCount(@retrieveIndividual) > 0 THEN

SET @individualId = Field(Row(@retrieveIndividual, 1), 'Id')
SET @updateIndividual = UpdateSingleSalesforceObject('Individual', @individualId, 'FII_IND_SEL_Molestar__c', 'No Ofertas', 'FII_IND_SEL_Iden_Evi__c', 'Landing SFMC')

ELSE

SET @retrieveNames = RetrieveSalesforceObjects('Contact', 'FirstName, LastName', 'Id', '=', @contactIdAmpscript)
SET @firstName = Field(Row(@retrieveNames, 1), 'FirstName')
SET @lastName = Field(Row(@retrieveNames, 1), 'LastName')
SET @createIndividual = CreateSalesforceObject('Individual', 5, 'Contact__c', @contactIdAmpscript, 'FII_IND_SEL_Molestar__c', 'No Ofertas', 'FII_IND_SEL_Iden_Evi__c', 'Landing SFMC', 'FirstName', @firstName, 'LastName', @lastName)

ENDIF

]%%

<script runat="server">

                var individualId = Variable.GetValue("@individualId")
                var updateIndividual = Variable.GetValue("@updateIndividual")
                var createIndividual = Variable.GetValue("@createIndividual")

                var rows = Platform.Function.UpsertData("DE_S010528_ATC_CAM_DIG_ML_Captacion_Email_Registros_Landing", ["SubscriberKey"], [ContactId], ["Email", "AccountId", "Tipo_Documento", "Numero_Documento", "CurrentDate", "CheckboxPolProtDatos", "CheckboxOtrasCom", "CaseId", "TaskId", "IndividualId", "NewIndividualId"], [Email, AccountId, accountData.tipoDocumento, nDocumento, today, proteccionDatos, otrasComunicaciones, createCase, createTask, individualId, createIndividual]);
                Write('true')

              } else {
                var rows = Platform.Function.UpsertData("DE_S010528_ATC_CAM_DIG_ML_Captacion_Email_Registros_Landing", ["SubscriberKey"], [ContactId], ["Email", "AccountId", "Tipo_Documento", "Numero_Documento", "CurrentDate", "CheckboxPolProtDatos", "CheckboxOtrasCom", "CaseId", "TaskId"], [Email, AccountId, accountData.tipoDocumento, nDocumento, today, proteccionDatos, otrasComunicaciones, createCase, createTask]);
                Write('true');
              }

            } else {
              var rows = Platform.Function.UpsertData("DE_S010528_ATC_CAM_DIG_ML_Captacion_Email_Registros_Landing", ["SubscriberKey"], [ContactId], ["Email", "AccountId", "Tipo_Documento", "Numero_Documento", "CurrentDate", "CheckboxPolProtDatos", "CheckboxOtrasCom", "Error", "CaseId"], [Email, AccountId, accountData.tipoDocumento, nDocumento, today, proteccionDatos, otrasComunicaciones, 'La Task no ha podido crearse', createCase]);
              Write('false')
            }

          } else {
            var rows = Platform.Function.UpsertData("DE_S010528_ATC_CAM_DIG_ML_Captacion_Email_Registros_Landing", ["SubscriberKey"], [ContactId], ["Email", "AccountId", "Tipo_Documento", "Numero_Documento", "CurrentDate", "CheckboxPolProtDatos", "CheckboxOtrasCom", "Error"], [Email, AccountId, accountData.tipoDocumento, nDocumento, today, proteccionDatos, otrasComunicaciones, 'El Case no ha podido crearse']);
            Write('false')
          }

        } else {
          var rows = Platform.Function.UpsertData("DE_S010528_ATC_CAM_DIG_ML_Captacion_Email_Registros_Landing", ["SubscriberKey"], [ContactId], ["Email", "AccountId", "Tipo_Documento", "Numero_Documento", "CurrentDate", "CheckboxPolProtDatos", "CheckboxOtrasCom", "Error"], [Email, AccountId, accountData.tipoDocumento, nDocumento, today, proteccionDatos, otrasComunicaciones, 'Ha habido un error al modificar el email']);
          Write('false');
        }

      } else {
        var rows = Platform.Function.UpsertData("DE_S010528_ATC_CAM_DIG_ML_Captacion_Email_Registros_Landing", ["SubscriberKey"], [ContactId], ["Email", "AccountId", "Tipo_Documento", "Numero_Documento", "CurrentDate", "CheckboxPolProtDatos", "CheckboxOtrasCom", "Error"], [Email, AccountId, accountData.tipoDocumento, nDocumento, today, proteccionDatos, otrasComunicaciones, 'El número de documento no coincide']);
        Write('false');
      }
    } else {
      var rows = Platform.Function.UpsertData("DE_S010528_ATC_CAM_DIG_ML_Captacion_Email_Registros_Landing", ["SubscriberKey"], [ContactId], ["Email", "AccountId", "CurrentDate", "CheckboxPolProtDatos", "CheckboxOtrasCom", "Error"], [Email, AccountId, today, proteccionDatos, otrasComunicaciones, 'No se pudo recuperar información de la cuenta.']);
      Write('false');
    }

  }

  catch (error) {
    var rows = Platform.Function.UpsertData("DE_S010528_ATC_CAM_DIG_ML_Captacion_Email_Registros_Landing", ["SubscriberKey"], [ContactId], ["Email", "AccountId", "CurrentDate", "CheckboxPolProtDatos", "CheckboxOtrasCom", "Error"], [Email, AccountId, today, proteccionDatos, otrasComunicaciones, 'Se ha producido un error en el proceso'])
    Write('false')    
  }
</script>
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter