<?xml version="1.0" encoding="utf-8"?>
<AutoMateTask>
  <TaskInfo>
    <Version TaskVersion="11.6.0.70" MinVersion="0.0.0.0" AMLVersion="3.0" />
  </TaskInfo>
  <TaskVariables>
    <TaskVariable Name="TaskVar_MainPath" Default="C:\Automate\Tasks\%GetTaskName()%" />
    <TaskVariable Name="TaskVar_ElapsedTime" />
    <TaskVariable Name="TaskVar_Log" Default="%TaskVar_MainPath%\Logs\%GetTaskName()%_%format(Now(), &quot;yyyy-MM-dd hhmmss&quot;)%.log" />
    <TaskVariable Name="TaskVar_errorTitle" Default="We found an error on the task %GetTaskName()%" />
    <TaskVariable Name="TaskVar_errorDesc" />
    <TaskVariable Name="TaskVar_DownloadFolder" Default="C:\Users\%Split(GetUsername(), &quot;\&quot;)(1)%\Downloads" />
    <TaskVariable Name="TaskVar_ScreenShot" Default="%TaskVar_MainPath%\ScreenShot\%GetTaskName()%_%format(Now(), &quot;yyyyMMdd&quot;)%.jpg" />
    <TaskVariable Name="TaskVar_Iterations" Default="1" />
    <TaskVariable Name="TaskVar_ErrorHTML" />
    <TaskVariable Name="TaskVar_bodySUCCESS" />
    <TaskVariable Name="TaskVar_bodyERROR" />
    <TaskVariable Name="TaskVar_ErrorSubject" Default="Task %GetTaskName()% has failed." />
    <TaskVariable Name="TaskVar_SuccessSubject" Default="Task %GetTaskName()% has finished succesfully." />
    <TaskVariable Name="TaskVar_Error" />
    <TaskVariable Name="TaskVar_Needle" Default="%TaskVar_MainPath%\Needle" />
    <TaskVariable Name="TaskVar_HTMLClient" Default="Automate, a division of HelpSystems %year(now())%." />
    <TaskVariable Name="var_ErrorMsg" Description="For Error messages handling" />
    <TaskVariable Name="var_SAPTaskBarMsg" Description="Message in the SAP Status Bar" />
    <TaskVariable Name="var_ExcelReplace" Description="Replace file if exists already? 0 = NO, 1 = YES." Default="0" />
    <TaskVariable Name="var_FilePath" />
    <TaskVariable Name="var_FileName" />
    <TaskVariable Name="var_CustomerAccount" />
    <TaskVariable Name="var_CompanyCode" />
    <TaskVariable Name="var_PostingDateFrom" />
    <TaskVariable Name="var_PostingDateTo" />
  </TaskVariables>
  <TaskFunctions>
    <TaskFunction Name="OnStepStart" Access="private">
      <Parameters>
        <Parameter Name="FunctionName" Description="The function that is starting the step" />
        <Parameter Name="StepNumber" Description="The step number that is about to execute" />
      </Parameters>
    </TaskFunction>
    <TaskFunction Name="OnStepEnd" Access="private">
      <Parameters>
        <Parameter Name="FunctionName" Description="The function that is ending the step" />
        <Parameter Name="StepNumber" Description="The step number that is about to end" />
      </Parameters>
    </TaskFunction>
    <TaskFunction Name="OnStepError" Access="private">
      <Parameters>
        <Parameter Name="FunctionName" Description="The function with the error" />
        <Parameter Name="StepNumber" Description="The step number of the error" />
        <Parameter Name="ErrorText" Description="The text of the error" />
        <Parameter Name="ErrorCode" Description="The code of the error" />
      </Parameters>
    </TaskFunction>
    <TaskFunction Name="OnTaskFailure" Access="private">
      <Parameters>
        <Parameter Name="FunctionName" Description="The function causing the task failure" />
        <Parameter Name="StepNumber" Description="The step number causing the task failure" />
        <Parameter Name="ErrorText" Description="The text of the error" />
        <Parameter Name="ErrorCode" Description="The code of the error" />
      </Parameters>
      <Steps>
<AMVARIABLE ACTIVITY="set" VARIABLENAME="TaskVar_error"><![CDATA[<strong>%AMError.FunctionName%</strong> in the Step <strong>%AMError.StepNumber%</strong>. Error Description: <span style="color: #ff0000;"><strong>"%AMError.ErrorDesc%"</strong></span>]]></AMVARIABLE>
<AMTIMER ACTIVITY="stop" RESULTVARIABLE="TaskVar_ElapsedTime" SESSION="TimerSession1" />
<AMIMAGE ACTIVITY="capture_screen" FILE="%TaskVar_ScreenShot%" />
<AMFILESYSTEM ACTIVITY="write_file" FILE="%TaskVar_Log%">%NOW()% - ERROR - Error found on the Function %Replace(Replace(Replace(Replace(Replace(Replace(TaskVar_Error, "&lt;span style=""color: #ff0000;""&gt;", "", 1, -1), "&lt;p&gt;&amp;lt;", "", 1, -1), "&lt;/strong&gt;", "", 1, -1), "&lt;strong&gt;", "", 1, -1), "&lt;p&gt;&amp;lt;&lt;strong&gt;", "", 1, -1), "&lt;/span&gt;", "", 1, -1)%. You can check the ScreenShot at: %TaskVar_ScreenShot%
%NOW()% - INFO - Aborting task. Total elapsed time: %Round(TaskVar_ElapsedTime, 2)% seconds.</AMFILESYSTEM>
<!--The previous 3 steps are for getting the errors into a variable.-->
<!--Let's create our subject for notifications in case of failure-->
<AMVARIABLE ACTIVITY="set" VARIABLENAME="TaskVar_ErrorSubject"><![CDATA[Error found on %GetTaskName()%]]></AMVARIABLE>
<!--Set text on the BODY for our failure notification-->
<AMVARIABLE ACTIVITY="set" VARIABLENAME="TaskVar_bodyERROR"><![CDATA[An error has been found in the task %GetTaskName()% on the Function %TaskVar_error%. Task was aborted.
<br><br>
Attached, you will find Screen Shot and Log file.
<br><br>
Total elapsed time: %Round(TaskVar_ElapsedTime, 2)% seconds.<br><br>]]></AMVARIABLE>
<!--Let's send the Email &#45; disabled by default &#45; REMEMBER to create the %constant_administratorEmail% or set the value in case it's already created-->
<AMEMAIL ACTIVITY="send" SESSION="NotificationEmail" FROM="Automate@helpsystems.com" TO="%constant_AdministratorEmail%" SUBJECT="Automate Plus Notificacion - %TaskVar_ErrorSubject%" HTML="YES" ATTACH="%TaskVar_Log%;%AMAttachment.automateerror%;%TaskVar_ScreenShot%;%AMAttachment.Client_logo_footer%;%AMAttachment.Client_logo_header%" AM_ENABLED="NO">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;HelpSystems&lt;/title&gt;
&lt;meta charset="utf-8"&gt;
&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
&lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
&lt;style type="text/css"&gt;
    /* CLIENT-SPECIFIC STYLES */
    #outlook a{padding:0;} /* Force Outlook to provide a "view in browser" message */
    .ReadMsgBody{width:100%%;} .ExternalClass{width:100%%;} /* Force Hotmail to display emails at full width */
    .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%%;} /* Force Hotmail to display normal line spacing */
    body, table, td, a{-webkit-text-size-adjust:100%%; -ms-text-size-adjust:100%%;} /* Prevent WebKit and Windows mobile changing default text sizes */
    table, td{mso-table-lspace:0pt; mso-table-rspace:0pt;} /* Remove spacing between tables in Outlook 2007 and up */
    img{-ms-interpolation-mode:bicubic;} /* Allow smoother rendering of resized image in Internet Explorer */

    /* RESET STYLES */
    body{margin:0; padding:0;}
    img{border:0; height:auto; line-height:100%%; outline:none; text-decoration:none;}
    table{border-collapse:collapse !important;}
    body{height:100%% !important; margin:0; padding:0; width:100%% !important;}

    /* iOS BLUE LINKS */
    .appleBody a {color:#0072C6; text-decoration: none;}
    .appleFooter a {color:#dcdcdc;}

    /* MOBILE STYLES */
    @media screen and (max-width: 525px) {

        /* ALLOWS FOR FLUID TABLES */
        table[class="wrapper"]{
          width:100%% !important;
        }

        /* ADJUSTS LAYOUT OF LOGO IMAGE */
        td[class="logo"]{
          text-align: center;
          padding: 5px 0 5px 0 !important;
        }

        td[class="logo"] img{
          margin:0 auto!important;
        }

        /* USE THESE CLASSES TO HIDE CONTENT ON MOBILE */
        td[class="mobile-hide"]{
          display:none;}

        img[class="mobile-hide"]{
          display: none !important;
        }

        img[class="img-max"]{
          max-width: 100%% !important;
          height:auto !important;
        }

        /* FULL-WIDTH TABLES */
        table[class="responsive-table"]{
          width:100%%!important;
        }

        /* UTILITY CLASSES FOR ADJUSTING PADDING ON MOBILE */
        td[class="padding"]{
          padding: 10px 5%% 15px 5%% !important;
        }
  
  td[class="padding-copy"]{
          padding: 30px 5%% 20px 5%% !important;
          text-align: center;
        }

        td[class="padding-copy-headline"]{
          padding: 5px 5%% 0px 5%% !important;
          text-align: center;
        }
  
  td[class="padding-copy-subhead"]{
          padding: 10px 5%% 30px 5%% !important;
          text-align: center;
        }
  
  td[class="padding-copy-hero"]{
          padding: 0px 5%% 5px 5%% !important;
          text-align: center;
        }

        td[class="padding-meta"]{
          padding: 30px 5%% 0px 5%% !important;
          text-align: center;
        }

        td[class="no-pad"]{
          padding: 0 0 20px 0 !important;
        }

        td[class="no-padding"]{
          padding: 0 !important;
        }

        td[class="section-padding"]{
          padding: 25px 15px 0px 15px !important;
        }
  
  td[class="section-padding-button"]{
          padding: 30px 15px 30px 15px !important;
        }

        td[class="section-padding-bottom-image"]{
          padding: 20px 15px 0 15px !important;
        }

        /* ADJUST BUTTONS ON MOBILE */
        td[class="mobile-wrapper"]{
            padding: 10px 5%% 15px 5%% !important;
        }

        table[class="mobile-button-container"]{
            margin:0 auto;
            width:100%% !important;
        }

        a[class="mobile-button"]{
            width:80%% !important;
            padding: 15px !important;
            border: 0 !important;
            font-size: 16px !important;
        }

    }
&lt;/style&gt;
&lt;/head&gt;
&lt;body style="margin: 0; padding: 0;"&gt;

&lt;!-- HEADER --&gt;
&lt;table border="0" cellpadding="0" cellspacing="0" width="100%%" style="min-width:100%%;"&gt;
    &lt;tr&gt;
        &lt;td bgcolor="#3b3b3b"&gt;
            &lt;!-- HIDDEN PREHEADER TEXT --&gt;
            &lt;div style="display: none; font-size: 1px; color: #fefefe; line-height: 1px; font-family: Verdana, Geneva, sans-serif; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden;"&gt;
                HelpSystems
            &lt;/div&gt;
            &lt;div align="center" style="padding: 0px 5px 0px 5px;"&gt;
                &lt;table border="0" cellpadding="0" cellspacing="0" width="500" class="wrapper"&gt;
                    &lt;!-- LOGO/PREHEADER TEXT --&gt;
                    &lt;tr&gt;
                        &lt;td style="padding: 5px 0px 5px 0px;" class="logo"&gt;
                            &lt;table border="0" cellpadding="0" cellspacing="0" width="100%%" bgcolor="#3b3b3b"&gt;
                                &lt;tr&gt;
                                    &lt;td bgcolor="#3b3b3b" width="100" align="center"&gt;&lt;a href="https://community.helpsystems.com" target="_blank"&gt;&lt;img alt="HelpSystems" src="cid:Client_logo_header.jpg" width="156" height="44" style="font-family: Verdana, Geneva, sans-serif; color: #dcdcdc; font-size: 12px;" border="0"&gt;&lt;/a&gt;&lt;/td&gt;
                                &lt;/tr&gt;
                            &lt;/table&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/table&gt;
            &lt;/div&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;

&lt;!-- ONE COLUMN SECTION --&gt;
&lt;table border="0" cellpadding="0" cellspacing="0" width="100%%" style="min-width:100%%;"&gt;
    &lt;tr&gt;
        &lt;td bgcolor="#FFFFFF" align="center" style="padding: 50px 15px 10px 15px;" class="section-padding"&gt;
            &lt;table border="0" cellpadding="0" cellspacing="0" width="500" class="responsive-table"&gt;
                &lt;tr&gt;
                    &lt;td&gt;
                        &lt;table width="100%%" border="0" cellspacing="0" cellpadding="0"&gt;
                            &lt;tr&gt;
                                &lt;!-- HERO IMAGE --&gt;
                               &lt;td class="padding-copy-hero"&gt;
                               &lt;table width="100%%" border="0" cellspacing="0" cellpadding="0"&gt;
                                    &lt;tr&gt;
                                        &lt;td align="center"&gt;
                                            &lt;a href="https://community.helpsystems.com" target="_blank"&gt;&lt;img src="cid:automate-iconERROR.png" width="100" border="0" alt="" style="display: block; padding: 0 0 30px 0; color: #266e9c; text-decoration: none; font-family: Verdana, Geneva, sans-serif; font-size: 16px;" class="img-max"&gt;&lt;/a&gt;
                                           &lt;/td&gt;
                                       &lt;td align="left" style="font-family: Verdana-bold, Geneva, sans-serif; color:#2B2B2B; font-size:25px; line-height:35px; padding: 0 0 30px 20px" &gt;Automate Plus Notification&lt;/td&gt;
                                       
                                  &lt;/table&gt;
                           
                               &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td&gt;

                                &lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;


&lt;!-- ONE COLUMN SECTION --&gt;
&lt;table border="0" cellpadding="0" cellspacing="0" width="100%%" style="min-width:100%%;"&gt;
    &lt;tr&gt;
        &lt;td bgcolor="#FFFFFF" align="center" style="padding: 10px 15px 100px 15px;" class="section-padding-button"&gt;
            &lt;table border="0" cellpadding="0" cellspacing="0" width="500" class="responsive-table"&gt;
                &lt;tr&gt;
                    &lt;td&gt;
                        &lt;table width="100%%" border="0" cellspacing="0" cellpadding="0"&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                                    &lt;!-- COPY --&gt;
                                    &lt;table width="100%%" border="0" cellspacing="0" cellpadding="0"&gt;
          
          &lt;tr&gt;
                                                        &lt;td align="left" style="padding: 15px 0 0 0; font-family: Verdana, Geneva, sans-serif; color: #333333; font-size: 24px;" bgcolor="#FFFFFF"&gt;
&lt;strong&gt;%TaskVar_ErrorSubject%&lt;/strong&gt;&lt;/td&gt;
                                                    &lt;/tr&gt;
                                        &lt;tr&gt;
                                                        &lt;td align="left" style="padding: 15px 0 0 0; font-family: Verdana, Geneva, sans-serif; color: #333333; font-size: 16px;" bgcolor="#FFFFFF"&gt;
														%TaskVar_BodyERROR%

                                    &lt;/table&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
        &lt;td class="innerpadding borderbottom"&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
                        &lt;/table&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
           
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;

&lt;!-- FOOTER --&gt;
&lt;table border="0" cellpadding="0" cellspacing="0" width="100%%" style="min-width:100%%;"&gt;
    &lt;tr&gt;
        &lt;td bgcolor="#3b3b3b" align="center" style="padding: 20px 0px;"&gt;
            &lt;!-- UNSUBSCRIBE COPY --&gt;
            &lt;table cellpadding="0" cellspacing="0" width="100%%" border="0" style="max-width: 500px;" class="container"&gt;
                &lt;tbody&gt;&lt;tr&gt;
                  &lt;td align="center" style="padding-bottom: 20px;"&gt;&lt;table cellspacing="0" cellpadding="0" border="0" width="500" class="responsive-table"&gt;
                    &lt;tbody&gt;
                      &lt;tr&gt;
                        &lt;td align="center" style="font-size: 15px; line-height: 16px; font-family: Verdana, Geneva, sans-serif; color: #dcdcdc;" class="appleFooter"&gt;&lt;a href="https://www.helpsystems.com" target="_blank"&gt;&lt;img src="cid:Client_logo_footer.png" width="140" height="50" border="0" style="display: block;" alt="HelpSystems"&gt;&lt;/a&gt;&lt;br&gt;® %TaskVar_HTMLClient%&lt;/td&gt;
                      &lt;/tr&gt;
                    &lt;/tbody&gt;
                  &lt;/table&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;/body&gt;
&lt;/html&gt;</AMEMAIL>
<AMTASK ACTIVITY="stop" />
	</Steps>
    </TaskFunction>
    <TaskFunction Name="OnTaskStart" Access="private">
      <Parameters>
        <Parameter Name="Reason" Description="The reason the task is starting" />
      </Parameters>
      <Steps>
<!--Initiating our log-->
<AMTIMER SESSION="TimerSession1" />
<!--Let's write on the log file we've created -->
<AMFILESYSTEM ACTIVITY="write_file" FILE="%TaskVar_Log%">%Now()% - INFO - Starting the task "%GetTaskName()%"</AMFILESYSTEM>
<!--Lets create our main path in case does not exist-->
<AMIF ACTIVITY="folder_exist" ACCESSIBILITYENGINE="active" FOLDER="%TaskVar_MainPath%" MODE="not_exist" />
<AMFILESYSTEM ACTIVITY="create_folder" FOLDER="%TaskVar_MainPath%" />
<AMIF ACTIVITY="end" ACCESSIBILITYENGINE="active" />
<!--Let's create the folder to save our images (screenshots)-->
<AMIF ACTIVITY="folder_exist" ACCESSIBILITYENGINE="active" FOLDER="%TaskVar_MainPath%\ScreenShot" MODE="not_exist" />
<AMFILESYSTEM ACTIVITY="create_folder" AM_ONERROR="CONTINUE" FOLDER="%TaskVar_MainPath%\ScreenShot" />
<AMIF ACTIVITY="end" ACCESSIBILITYENGINE="active" />
<!--Let's create a needle folder, a needle is the part of the image you are looking for in a whole image-->
<AMIF ACTIVITY="folder_exist" ACCESSIBILITYENGINE="active" FOLDER="%TaskVar_Needle%" MODE="not_exist" />
<AMFILESYSTEM ACTIVITY="create_folder" AM_ONERROR="CONTINUE" FOLDER="%TaskVar_Needle%" />
<AMIF ACTIVITY="end" ACCESSIBILITYENGINE="active" />
<!--Here's our e&#45;mail session configuration, remember to create the following constatns (disabled by default):
%constant_SMTPuser%
%constant_SMTPpassword%
%constant_SMTPserver%-->
<AMEMAIL ACTIVITY="create_session" SESSION="NotificationEmail" PROTOCOLTYPE="smtp" SERVER="%constant_SMTPserver%" PORT="465" USERNAME="%constant_SMTPuser%" PASSWORD="AM50VkXMLAjKWtqsL8Qmf+h4Di5vwYYhwEsoyOs1MKEjAc=aME" SECURITY="implicit" IGNOREINVALIDCERTIFICATE="YES" TLSCIPHERS="All" TLSVERSIONS="Any" AM_ENABLED="NO" />
<!--Until we manage sessionss... we close!-->
<AMPROCESSES ACTIVITY="end" AM_ONERROR="CONTINUE" PROCESSNAME="saplogon.exe" CLOSEMESSAGE="NO" SAMEPROCESS="all" />
<AMWAIT ACCESSIBILITYENGINE="active" SCALAR="2" />
<AMIF ACTIVITY="process_running" ACCESSIBILITYENGINE="active" PROCESSACTION="end" PROCESS="Saplogon.exe" />
<AMRUN FILE="%const_SapLogonPath%" />
<AMWAIT ACTIVITY="window" ACCESSIBILITYENGINE="active" WINDOWTITLE="SAP Logon*" />
<AMIF ACTIVITY="end" ACCESSIBILITYENGINE="active" />
	</Steps>
    </TaskFunction>
    <TaskFunction Name="OnTaskEnd" Access="private">
      <Parameters>
        <Parameter Name="Reason" Description="The reason the task is ending" />
      </Parameters>
      <Steps>
<AMPROCESSES ACTIVITY="end" AM_ONERROR="CONTINUE" PROCESSNAME="saplogon.exe" CLOSEMESSAGE="NO" SAMEPROCESS="all" />
<!--Stop the timer to write down on the log file the elapsed time.-->
<AMTIMER ACTIVITY="stop" RESULTVARIABLE="TaskVar_ElapsedTime" SESSION="TimerSession1" />
<AMFILESYSTEM ACTIVITY="write_file" FILE="%TaskVar_Log%">%now()% - INFO - Ending our task
%now()% - INFO - The Task %GetTaskName()% has finished without errors
%now()% - INFO - Elapsed time: %Round(TaskVar_ElapsedTime, 2)% seconds
---------------------------------------------------------------------------------------</AMFILESYSTEM>
<!--Subject for our email notification-->
<AMVARIABLE ACTIVITY="set" VARIABLENAME="TaskVar_SuccessSubject"><![CDATA[The task %GetTaskName()% was completed successfully.]]></AMVARIABLE>
<!--Body for our email notification-->
<AMVARIABLE ACTIVITY="set" VARIABLENAME="TaskVar_bodySUCCESS"><![CDATA[Total elapsed time: %Round(TaskVar_ElapsedTime, 2)% seconds<br>
Attached, you will find the task log file.]]></AMVARIABLE>
<!--Let's send the Email &#45; disabled by default &#45; REMEMBER to create the %constant_administratorEmail% or set the value in case it's already created-->
<AMEMAIL ACTIVITY="send" SESSION="NotificationEmail" FROM="Automate@helpsystems.com" TO="%constant_AdministratorEmail%" SUBJECT="Automate Plus Notificacion - %TaskVar_SuccessSubject%" HTML="YES" ATTACH="%TaskVar_Log%;%AMAttachment.Client_logo_header%;%AMAttachment.Client_logo_footer%;%AMAttachment.automatesuccess%" AM_ENABLED="NO">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;HelpSystems&lt;/title&gt;
&lt;meta charset="utf-8"&gt;
&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
&lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
&lt;style type="text/css"&gt;
    /* CLIENT-SPECIFIC STYLES */
    #outlook a{padding:0;} /* Force Outlook to provide a "view in browser" message */
    .ReadMsgBody{width:100%%;} .ExternalClass{width:100%%;} /* Force Hotmail to display emails at full width */
    .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%%;} /* Force Hotmail to display normal line spacing */
    body, table, td, a{-webkit-text-size-adjust:100%%; -ms-text-size-adjust:100%%;} /* Prevent WebKit and Windows mobile changing default text sizes */
    table, td{mso-table-lspace:0pt; mso-table-rspace:0pt;} /* Remove spacing between tables in Outlook 2007 and up */
    img{-ms-interpolation-mode:bicubic;} /* Allow smoother rendering of resized image in Internet Explorer */

    /* RESET STYLES */
    body{margin:0; padding:0;}
    img{border:0; height:auto; line-height:100%%; outline:none; text-decoration:none;}
    table{border-collapse:collapse !important;}
    body{height:100%% !important; margin:0; padding:0; width:100%% !important;}

    /* iOS BLUE LINKS */
    .appleBody a {color:#0072C6; text-decoration: none;}
    .appleFooter a {color:#dcdcdc;}

    /* MOBILE STYLES */
    @media screen and (max-width: 525px) {

        /* ALLOWS FOR FLUID TABLES */
        table[class="wrapper"]{
          width:100%% !important;
        }

        /* ADJUSTS LAYOUT OF LOGO IMAGE */
        td[class="logo"]{
          text-align: center;
          padding: 5px 0 5px 0 !important;
        }

        td[class="logo"] img{
          margin:0 auto!important;
        }

        /* USE THESE CLASSES TO HIDE CONTENT ON MOBILE */
        td[class="mobile-hide"]{
          display:none;}

        img[class="mobile-hide"]{
          display: none !important;
        }

        img[class="img-max"]{
          max-width: 100%% !important;
          height:auto !important;
        }

        /* FULL-WIDTH TABLES */
        table[class="responsive-table"]{
          width:100%%!important;
        }

        /* UTILITY CLASSES FOR ADJUSTING PADDING ON MOBILE */
        td[class="padding"]{
          padding: 10px 5%% 15px 5%% !important;
        }
		
		td[class="padding-copy"]{
          padding: 30px 5%% 20px 5%% !important;
          text-align: center;
        }

        td[class="padding-copy-headline"]{
          padding: 5px 5%% 0px 5%% !important;
          text-align: center;
        }
		
		td[class="padding-copy-subhead"]{
          padding: 10px 5%% 30px 5%% !important;
          text-align: center;
        }
		
		td[class="padding-copy-hero"]{
          padding: 0px 5%% 5px 5%% !important;
          text-align: center;
        }

        td[class="padding-meta"]{
          padding: 30px 5%% 0px 5%% !important;
          text-align: center;
        }

        td[class="no-pad"]{
          padding: 0 0 20px 0 !important;
        }

        td[class="no-padding"]{
          padding: 0 !important;
        }

        td[class="section-padding"]{
          padding: 25px 15px 0px 15px !important;
        }
		
		td[class="section-padding-button"]{
          padding: 30px 15px 30px 15px !important;
        }

        td[class="section-padding-bottom-image"]{
          padding: 20px 15px 0 15px !important;
        }

        /* ADJUST BUTTONS ON MOBILE */
        td[class="mobile-wrapper"]{
            padding: 10px 5%% 15px 5%% !important;
        }

        table[class="mobile-button-container"]{
            margin:0 auto;
            width:100%% !important;
        }

        a[class="mobile-button"]{
            width:80%% !important;
            padding: 15px !important;
            border: 0 !important;
            font-size: 16px !important;
        }

    }
&lt;/style&gt;
&lt;/head&gt;
&lt;body style="margin: 0; padding: 0;"&gt;

&lt;!-- HEADER --&gt;
&lt;table border="0" cellpadding="0" cellspacing="0" width="100%%" style="min-width:100%%;"&gt;
    &lt;tr&gt;
        &lt;td bgcolor="#3b3b3b"&gt;
            &lt;!-- HIDDEN PREHEADER TEXT --&gt;
            &lt;div style="display: none; font-size: 1px; color: #fefefe; line-height: 1px; font-family: Verdana, Geneva, sans-serif; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden;"&gt;
                HelpSystems
            &lt;/div&gt;
            &lt;div align="center" style="padding: 0px 5px 0px 5px;"&gt;
                &lt;table border="0" cellpadding="0" cellspacing="0" width="500" class="wrapper"&gt;
                    &lt;!-- LOGO/PREHEADER TEXT --&gt;
                    &lt;tr&gt;
                        &lt;td style="padding: 5px 0px 5px 0px;" class="logo"&gt;
                            &lt;table border="0" cellpadding="0" cellspacing="0" width="100%%" bgcolor="#3b3b3b"&gt;
                                &lt;tr&gt;
                                    &lt;td bgcolor="#3b3b3b" width="100" align="center"&gt;&lt;a href="https://www.helpsystems.com" target="_blank"&gt;&lt;img alt="HelpSystems" src="cid:Client_logo_header.jpg" width="156" height="44" style="font-family: Verdana, Geneva, sans-serif; color: #dcdcdc; font-size: 12px;" border="0"&gt;&lt;/a&gt;&lt;/td&gt;
                                &lt;/tr&gt;
                            &lt;/table&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/table&gt;
            &lt;/div&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;

&lt;!-- ONE COLUMN SECTION --&gt;
&lt;table border="0" cellpadding="0" cellspacing="0" width="100%%" style="min-width:100%%;"&gt;
    &lt;tr&gt;
        &lt;td bgcolor="#FFFFFF" align="center" style="padding: 50px 15px 10px 15px;" class="section-padding"&gt;
            &lt;table border="0" cellpadding="0" cellspacing="0" width="500" class="responsive-table"&gt;
                &lt;tr&gt;
                    &lt;td&gt;
                        &lt;table width="100%%" border="0" cellspacing="0" cellpadding="0"&gt;
                            &lt;tr&gt;
                                &lt;!-- HERO IMAGE --&gt;
                              	&lt;td class="padding-copy-hero"&gt;
                               &lt;table width="100%%" border="0" cellspacing="0" cellpadding="0"&gt;
                                  		&lt;tr&gt;
                                      		&lt;td align="center"&gt;
                                          		&lt;a href="https://community.helpsystems.com" target="_blank"&gt;&lt;img src="cid:automate-iconSUCCESS.png" width="100" border="0" alt="" style="display: block; padding: 0 0 30px 0; color: #266e9c; text-decoration: none; font-family: Verdana, Geneva, sans-serif; font-size: 16px;" class="img-max"&gt;&lt;/a&gt;
                                          	&lt;/td&gt;
                                       &lt;td align="left" style="font-family: Verdana-bold, Geneva, sans-serif; color:#2B2B2B; font-size:25px; line-height:35px; padding: 0 0 30px 20px" &gt;Automate Plus Notification &lt;/td&gt;
                                       
                                  &lt;/table&gt;
                     		  		
                              	&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td&gt;

                                &lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;


&lt;!-- ONE COLUMN SECTION --&gt;
&lt;table border="0" cellpadding="0" cellspacing="0" width="100%%" style="min-width:100%%;"&gt;
    &lt;tr&gt;
        &lt;td bgcolor="#FFFFFF" align="center" style="padding: 10px 15px 100px 15px;" class="section-padding-button"&gt;
            &lt;table border="0" cellpadding="0" cellspacing="0" width="500" class="responsive-table"&gt;
                &lt;tr&gt;
                    &lt;td&gt;
                        &lt;table width="100%%" border="0" cellspacing="0" cellpadding="0"&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                                    &lt;!-- COPY --&gt;
                                    &lt;table width="100%%" border="0" cellspacing="0" cellpadding="0"&gt;
										
										&lt;tr&gt;
                                                        &lt;td align="left" style="padding: 15px 0 0 0; font-family: Verdana, Geneva, sans-serif; color: #333333; font-size: 24px;" bgcolor="#FFFFFF"&gt;
&lt;strong&gt;%TaskVar_SuccessSubject%&lt;/strong&gt;&lt;/td&gt;
                                                    &lt;/tr&gt;
                                        &lt;tr&gt;
                                                        &lt;td align="left" style="padding: 15px 0 0 0; font-family: Verdana, Geneva, sans-serif; color: #333333; font-size: 16px;" bgcolor="#FFFFFF"&gt;
														%TaskVar_bodySUCCESS%
                                       
                                    &lt;/table&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
        &lt;td class="innerpadding borderbottom"&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
                        &lt;/table&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
           
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;

&lt;!-- FOOTER --&gt;
&lt;table border="0" cellpadding="0" cellspacing="0" width="100%%" style="min-width:100%%;"&gt;
    &lt;tr&gt;
        &lt;td bgcolor="#3b3b3b" align="center" style="padding: 20px 0px;"&gt;
            &lt;!-- UNSUBSCRIBE COPY --&gt;
            &lt;table cellpadding="0" cellspacing="0" width="100%%" border="0" style="max-width: 500px;" class="container"&gt;
                &lt;tbody&gt;&lt;tr&gt;
                  &lt;td align="center" style="padding-bottom: 20px;"&gt;&lt;table cellspacing="0" cellpadding="0" border="0" width="500" class="responsive-table"&gt;
                    &lt;tbody&gt;
                      &lt;tr&gt;
                        &lt;td align="center" style="font-size: 15px; line-height: 16px; font-family: Verdana, Geneva, sans-serif; color: #dcdcdc;" class="appleFooter"&gt;&lt;a href="https://www.helpsystems.com" target="_blank"&gt;&lt;img src="cid:Client_logo_footer.png" width="140" height="50" border="0" style="display: block;" alt="HelpSystems"&gt;&lt;/a&gt;&lt;br&gt;® %TaskVar_HTMLClient%&lt;/td&gt;
                      &lt;/tr&gt;
                    &lt;/tbody&gt;
                  &lt;/table&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;/body&gt;
&lt;/html&gt;</AMEMAIL>
	</Steps>
    </TaskFunction>
    <TaskFunction Name="Main" Access="private">
      <Steps>
<!--SAP Bot : AR顧客明細をExcelに出力
説明 : このタスクは、TX:S_ALR_87012197を使用して指定された顧客/会社の品目を含むExcelファイルを生成します。
By Jose Garay-->
<AMREGION NAME="変数" />
<!--お客様のアカウント番号（必要ない場合は空白にしてください） -->
<AMVARIABLE ACTIVITY="set" VARIABLENAME="var_CustomerAccount" VALUE="3" />
<!--会社コード（不要な場合は空白にしてください。）-->
<AMVARIABLE ACTIVITY="set" VARIABLENAME="var_CompanyCode" VALUE="" />
<!--投稿日 From/To (SAPの日付形式を確認。不要な場合は空欄のままにしてください)-->
<AMVARIABLE ACTIVITY="set" VARIABLENAME="var_PostingDateFrom" VALUE="" />
<AMVARIABLE ACTIVITY="set" VARIABLENAME="var_PostingDateTo" VALUE="" />
<!--Excel出力ファイルのパスとファイル名-->
<AMVARIABLE ACTIVITY="set" VARIABLENAME="var_FilePath" VALUE="c:\test\" />
<AMVARIABLE ACTIVITY="set" VARIABLENAME="var_FileName"><![CDATA[Customer_%var_CustomerAccount%_Lines.xlsx]]></AMVARIABLE>
<AMENDREGION />
<!--カスタマーラインアイテムを含むExcelファイルを取得します。-->
<AMTASK ACTIVITY="call_function" FUNCTIONNAME="ExecuteSAPAction()" />
	</Steps>
    </TaskFunction>
    <TaskFunction Name="ExecuteSAPAction">
      <Steps>
<!--顧客項目リストを含むExcelファイルを取得する。-->
<AMSCRIPT><![CDATA[Public session
Public connection
Public ObjShell

Sub Main
    On Error GoTo ErrorHandler
    Set ObjShell = CreateObject("Wscript.Shell")

    'Log in to SAP session.
    LoginSAP()

    'Execute SAP Transaction
    'Using transaction S_ALR_87012197 for AR Customer Line Items
    ExetuteSAPTransaction("S_ALR_87012197")

    'Select filters and extract Excel.
    If session.Info.IsLowSpeedConnection() = vbTrue Then
        session.findById("wnd[0]/usr/ctxt[0]").Text = var_VendorAccount
        session.findById("wnd[0]/usr/ctxt[2]").Text = var_CompanyCode
        session.findById("wnd[0]/usr/ctxt[11]").Text = var_PostingDateFrom
        session.findById("wnd[0]/usr/ctxt[12]").Text = var_PostingDateTo

    Else
        session.findById("wnd[0]/usr/ctxtDD_KUNNR-LOW").Text = var_VendorAccount
        session.findById("wnd[0]/usr/ctxtDD_BUKRS-LOW").Text = var_CompanyCode
        session.findById("wnd[0]/usr/ctxtSO_BUDAT-LOW").Text = var_PostingDateFrom
        session.findById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").Text = var_PostingDateTo

    End If
    session.findById("wnd[0]").sendVKey 8
    Wait(1)
    ExportToExcel(var_FilePath,var_FileName,1)

    'Reset SAP and Logoff SAP
    ExetuteSAPTransaction("/n")
    LogoffSAP()

    ErrorHandler:
    If Err.Number <> 0 Then 
        ErrMyErrorHandler()
        CloseSAPConnections()
    End If

End Sub

Sub LoginSAP()
    On Error GoTo ErrorHandler
    var_ErrorMsg = ""
    
    If Not IsObject(SapGuiAuto) Then
        Set SapGuiAuto = GetObject("SAPGUI")
    End If
    
    If Not IsObject(application) Then
        Set application = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(Connection) Then
       Set Connection = application.Openconnection(const_SAPConnection, False)
    End If
    If Not IsObject(session) Then
       Set session    = Connection.Children(0)
    End If
    
    If IsObject(WScript) Then
       WScript.ConnectObject session,     "on"
       WScript.ConnectObject application, "on"
    End If
    session.findById("wnd[0]").maximize
    session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = const_SAPClientNumber
    session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = const_SAPUser
    session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = const_SAPPassword
    session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = const_SAPLanguage
    session.findById("wnd[0]").sendVKey 0
    Wait(1)
    If session.Children.Count = 2 Then
        On Error GoTo Enterkeypress
        WindowsMessage = session.findById("wnd[1]/usr/txtMULTI_LOGON_TEXT").Text
        WindowsMessage = "Session closed: " & WindowsMessage & " " & session.findById("wnd[1]/usr/txtMULTI_LOGON_TEXT2").Text
        'var_ErrorMsg = WindowsMessage
        If session.findById("wnd[1]/usr/radMULTI_LOGON_OPT1").Selected = vbFalse Then
            session.findById("wnd[1]/usr/radMULTI_LOGON_OPT1").Select()
            session.findById("wnd[1]").sendVKey 0
        End If
        Wait(1)
        If  ObjShell.AppActivate("SAP GUI for Windows 760") Then
            ObjShell.SendKeys "%{F4}"
        End If
        'In order to avoid any other information that might appear (example. license expiration). To be improved!
        Enterkeypress:
        session.findById("wnd[1]").sendVKey 0
    End If
    Exit Sub
    ErrorHandler:
    If Err.Number <> 0 Then ErrMyErrorHandler
End Sub

Sub ConnectExistingSAPSession()
    If Not IsObject(application) Then
       Set SapGuiAuto  = GetObject("SAPGUI")
       Set application = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(Connection) Then
       Set Connection = application.Children(0)
    End If
    If Not IsObject(session) Then
       Set session    = Connection.Children(0)
    End If
    If IsObject(WScript) Then
       WScript.ConnectObject session,     "on"
       WScript.ConnectObject application, "on"
    End If
End Sub

Sub ExetuteSAPTransaction(TX)
    If TX <>  "" Then
        session.findById("wnd[0]").maximize
        session.findById("wnd[0]/tbar[0]/okcd").Text = TX
        session.findById("wnd[0]").sendVKey 0
    Else
        var_ErrorMsg = "No transaction defined."
    End If
End Sub

Sub LogoffSAP()
    On Error GoTo ErrorHandler
    var_ErrorMsg = ""

    If  IsObject(session) Then
        session.findById("wnd[0]").maximize
        session.findById("wnd[0]/tbar[0]/btn[15]").press
        If session.Info.IsLowSpeedConnection() = vbTrue Then
            session.findById("wnd[1]/usr/btn[0]").press
        Else
            session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
        End If
    End If

    Exit Sub
    ErrorHandler:
    If Err.Number <> 0 Then ErrMyErrorHandler
End Sub

Sub ErrMyErrorHandler()
    If IsObject(session) Then
        If (session.findById("wnd[0]/sbar").messagetype = "E" Or session.findById("wnd[0]/sbar").messagetype = "W") Then
        ErrorMsg =  "SAP Status Bar Error: "& session.findById("wnd[0]/sbar/pane[0]").Text
        End If
    End If
    ErrorMsg = ErrorMsg & Chr(13) & Chr(10) &"Script Error: " & Err.Number & ". " & Err.Description
    var_ErrorMsg = ErrorMsg
End Sub

Sub ExportToExcel(FilePath,FileName,SaveReplace)
    session.findById("wnd[0]").sendVKey 43
    If session.Info.IsLowSpeedConnection() = vbTrue Then
        session.findById("wnd[1]/usr/rad[2]").setFocus
        session.findById("wnd[1]/usr/rad[2]").Select
        'Set format to excel xlsx
        session.findById("wnd[1]/usr/cmb").setFocus
        session.findById("wnd[1]/usr/cmb").Key "10"
        session.findById("wnd[1]/tbar[0]/btn[0]").press
        'Set path
        session.findById("wnd[1]/usr/ctxt[0]").Text  = FilePath
        'SetFilename
        session.findById("wnd[1]/usr/ctxt[1]").Text  = FileName
    Else
        session.findById("wnd[1]/usr/radRB_OTHERS").setFocus
        session.findById("wnd[1]/usr/radRB_OTHERS").Select
        'Set format to excel xlsx
        session.findById("wnd[1]/usr/cmbG_LISTBOX").setFocus
        session.findById("wnd[1]/usr/cmbG_LISTBOX").Key "10"
        session.findById("wnd[1]/tbar[0]/btn[0]").press
        'Set path
        session.findById("wnd[1]/usr/ctxtDY_PATH").Text  = FilePath
        'SetFilename
        session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text  = FileName
    End If
    If SaveReplace = "0" Then
    '   Save...
        session.findById("wnd[1]/tbar[0]/btn[0]").press
    Else
        'Replace...
        session.findById("wnd[1]/tbar[0]/btn[11]").press
    End If

End Sub

Sub CloseSAPConnections()
    If IsObject(session) Then
        Set session = Nothing
        connection.CloseConnection()
        Set connection = Nothing
        Set Application = Nothing
        Set SapGuiAuto = Nothing
    End If
End Sub]]></AMSCRIPT>
<!--エラー処理-->
<AMIF ACCESSIBILITYENGINE="active" EXPRESSION="%Trim(Len(var_ErrorMsg))% &lt;&gt; 0" />
<!--ログにエラーメッセージを書き込む-->
<AMFILESYSTEM ACTIVITY="write_file" FILE="%TaskVar_Log%">%Now()% - ERROR - We were unable to run the script
%Now()% - ERROR - Error description: %var_ErrorMsg%</AMFILESYSTEM>
<AMTASK ACTIVITY="stop" STATUSTYPE="ERROR" ERRORNUMBER="%const_SAPClientNumber%" ERRORTEXT="%var_ErrorMsg%" />
<AMELSE />
<AMIF ACCESSIBILITYENGINE="active" EXPRESSION="%Trim(Len(var_SAPTaskBarMsg))% &lt;&gt; 0" />
<!--ログにエラーメッセージを書き込む-->
<AMFILESYSTEM ACTIVITY="write_file" FILE="%TaskVar_Log%">%Now()% - ERROR - We were unable to run the script
%Now()% - ERROR - Error description: %var_SAPTaskBarMsg%</AMFILESYSTEM>
<AMTASK ACTIVITY="stop" STATUSTYPE="ERROR" ERRORNUMBER="%const_SAPClientNumber%" ERRORTEXT="%var_SAPTaskBarMsg%" />
<AMELSE />
<!--ログを書き込む-->
<AMFILESYSTEM ACTIVITY="write_file" FILE="%TaskVar_Log%">%Now()% - INFO - Script successfully run</AMFILESYSTEM>
<AMIF ACTIVITY="end" ACCESSIBILITYENGINE="active" />
<AMIF ACTIVITY="end" ACCESSIBILITYENGINE="active" />
	</Steps>
    </TaskFunction>
  </TaskFunctions>
</AutoMateTask>