Advanced Anaplan Connect Scripting Techniques

Anaplan Connect scripts can provide useful error detection and notification via custom batch commands and utilities. The basic script uses standard batch (or shell) scripting language to call Anaplan Connect client executable to run pre-built Anaplan actions and/or processes. The basic script can be enhanced by adding additional commands to captures runtime errors into text files, parse through these files to find specific errors/messages and send notifications including said errors/messages.
In order to send notifications an email utility capable of sending email in batch mode is required. Many of these utilities can be acquired as shareware free of charge. Which one to choose will depend on the email server. In the samples below the utility “bmail” is used.
Set up variables for evaluating whether an error is detected and if re-running the script is desired.
set /a ERRNO=0
set /a COUNT=0
set /a RETRY_COUNT=0
Set up Anaplan Connect parameters
set AnaplanUser=”{}”
set WorkspaceId=”{workspaceid}”
set ModelId=”{modelid}”
set Oper={anaplan connect operation commands}
Set up email parameters.
REM Set Email variables
set Domain=”{}”
set Smtp=”{}”
set User=”{}”
set Pass=”{email-password}”
set To=-t “{}” <-t “{}”>
set From=”{}”
set Subject=”{email subject}”
Set up error files and capture runtime output
REM Dynamically set logfile name based upon current date and retry count.
set LogFile=%date:~-4%-%date:~7,2%-%date:~4,2%-ANAPLAN-LOG-RUN-%COUNT%.TXTREM Delete prior log and error files
del {path}\BAT_STAT.TXT
del {path}\AC_API.ERRREM Out-of-the-box Anaplan Connect code with the exception of sending output to a log file
setlocal enableextensions enabledelayedexpansion || exit /b 1
REM Change the directory to the batch file’s drive, then change to its folder
cd %~dp0
if not %AnaplanUser% == “” set Credentials=-user %AnaplanUser%@echo {opeartion description} > {path}\%LogFile%
set Cmd=.\AnaplanClient.bat %Credentials% -workspace %WorkspaceId% -model %ModelId% %Oper%
@echo %Cmd% >> {path}\%LogFile%
cmd /C %Cmd% >> {path}\%LogFile%
Set up error/message search criteria and save to output file. In the example below “operation failed” and “Item not located” are used
@findstr /c:”operation failed” {path}\%LogFile% > {path}\AC_API.ERR
@findstr /c:”Item not located” {path}\%LogFile% >> {path}\AC_API.ERRREM Remove any 0K files produced by previous findstr commands
@for /r {path}\updateserrors %%f in (*) do if %%~zf==0 del “%%f”REM If the file AC_API.ERR exists then echo errors to the primary BAT_STAT log file
REM Else echo the log file to the primary BAT_STAT log file
@if exist {path}\AC_API.ERR (
) else (
Send notification. In the example below “bmail” is called to send an email in batch mode

bmail -s %Smtp% -f %From% -t %To% -a %Subject% -b “Please refer to attached log for any errors if applicable.” -m {path}\%LogFile%

Setup retry (optional)
@if exist {path}\AC_API.ERR (
@if %COUNT% lss %RETRY_COUNT% (
@set /a COUNT+=1
@goto :START
) else (
set /a ERRNO=1
@goto :END
) else (
set /a ERRNO=0

Leave a Reply