Script Update Current Date

New Contributor

Script Update Current Date

Hello,

 

I've read through the boards, and unless a topic is well hidden, I have been unable to solve what should be a simple solution. I have two issues:

A) I am unable to write ("copy") a script from previous posts to update the Current Date line item in my Current Date Module. I created a process on my computer to update the date daily (run the script), but it won't load into Anaplan.

 

 

#!/bin/sh
# This example uploads a file and runs an import

AnaplanUser=""
WorkspaceId=""
ModelId=""
set ServiceUrl="<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span><a href="<a href="https://api.anaplan.com" target="_blank">https://api.anaplan.com</a>" target="_blank"><a href="https://api.anaplan.com</a><span" target="_blank">https://api.anaplan.com</a><span</a> class="token punctuation">"</span></span> <span class="token attr-name">target</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>_blank<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><a href="<a href="https://api.anaplan.com" target="_blank">https://api.anaplan.com</a>" target="_blank"><a href="https://api.anaplan.com</a><span" target="_blank">https://api.anaplan.com</a><span</a> class="token tag"><span class="token tag"><span class="token punctuation"></</span>a</span><span class="token punctuation">></span></span>"

set AuthUrl="<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span><a href="<a href="https://auth.anaplan.com" target="_blank">https://auth.anaplan.com</a>" target="_blank"><a href="https://auth.anaplan.com</a><span" target="_blank">https://auth.anaplan.com</a><span</a> class="token punctuation">"</span></span> <span class="token attr-name">target</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>_blank<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><a href="<a href="https://auth.anaplan.com" target="_blank">https://auth.anaplan.com</a>" target="_blank"><a href="https://auth.anaplan.com</a><span" target="_blank">https://auth.anaplan.com</a><span</a> class="token tag"><span class="token tag"><span class="token punctuation"></</span>a</span><span class="token punctuation">></span></span>"

Set Filename="C:\Users\tobrien\Desktop\HDCCO\Scripts\Current Date.txt"

FOR /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set mm=%%a& set dd=%%b& set yyyy=% %c& (if "%%a:~0,1" gtr "9" set mm=%%b& set dd=%%c& set yyyy=%%d))

echo Todays date in Windows format is: %date%

set mydate=%yyyy%-%mm%-%dd%
echo 'Current Date': %mydate%

touch Current Date.txt
set snapshot=%mydate%
echo 'Latest Snapshot': %snapshot%

@echo "Current Date"> %FileName%
@echo "%mydate%">> %FileName%

#____________________________ Do not edit below this line ______________________________
setlocal enableextensions enabledelayedexpansion || exit /b 1
cd %~dp0
if not %AnaplanUser% == "" set Credentials=-certificate %AnaplanUser%
set Command=.\AnaplanClient.bat %Credentials% -workspace %WorkspaceId% -model %ModelId% %Operation%
@echo %Command%
cmd /c %Command%

 

 

 

B) After I assign the import to a process, then run the process manually, the date in the text file does not match the date in the Import Action.

Import Current Date.jpgtext file current date.jpg

20 REPLIES 20
Contributor

Re: Script Update Current Date

Is part of the script missing?  I do not see the operation line in which you upload the file that is created and run the import.

 

What type of messages do you get when you run this?

 

Scott

Message 2 of 21
Certified Master Anaplanner

Re: Script Update Current Date

Hi - it looks like you are missing the set operation line, currently it is just creating a date file but not running any action.  To do so: go into the target model and import your "current date.txt" file.  save the import action as "Current Date from current date.txt".  Then update the below script with your credentials/paths. Rerun the script.  As a note you should also "Set" the user, workspace, and model variables.  I have done this for you and run a few tests on the below to confirm it works.  Hope this helps.   -Jt  

 

@echo off

set AnaplanUser="[]"
set WorkspaceId="[]"
set ModelId="[]"


set Filename="[path]"

FOR /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set mm=%%a& set dd=%%b& set yyyy=% %c& (if "%%a:~0,1" gtr "9" set mm=%%b& set dd=%%c& set yyyy=%%d))

echo Todays date in Windows format is: %date%

set mydate=%yyyy%-%mm%-%dd%
echo 'Current Date': %mydate%

rem touch Current Date.txt
set snapshot=%mydate%
echo 'Latest Snapshot': %snapshot%

@echo "Current Date"> %FileName%
@echo "%mydate%">> %FileName%


set Operation=-service "https://api.anaplan.com" -auth "https://auth.anaplan.com" -file "current date.txt" -put "[path]" -import "Current Date from current date.txt" -execute


rem *** End of settings - Do not edit below this line ***
setlocal enableextensions enabledelayedexpansion || exit /b 1
cd %~dp0
if not %AnaplanUser% == "" set Credentials=-user %AnaplanUser%
set Command=.\AnaplanClient.bat %Credentials% -workspace %WorkspaceId% -model %ModelId% %Operation%
@echo %Command%
cmd /c %Command%
pause

Message 3 of 21
New Contributor

Re: Script Update Current Date

Thanks for both of your help in advance. I put in my username (which is my email), and now I'm getting the following error:

'.\AnaplanClient.bat' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . . .

 

also the "[path]" you had in the code, should that be the path of the file and the file name? ie "C:\Users\tobrien\Desktop\Scripts\Current Date.txt"  ?

Message 4 of 21
Certified Master Anaplanner

Re: Script Update Current Date

For the first point,  is your current date script in the same folder as the anaplanclient.bat?   I think that might be your issue, as you would want it to be (as an alternative you can specify the path in the "do not end below this line section", but would not recommend that for now).   

 

For the second point, yes full path including the file name ("C:\Users\tobrien\Desktop\Scripts\Current Date.txt").  Also make sure to update this path in both the "set file name" and "set operation" lines. 

 

Hope this helps resolve.

 

Jt

Message 5 of 21
New Contributor

Re: Script Update Current Date

Thanks JT,

 

I'm was getting the following error, but I fixed it:

"" -execute
Java was unexpected at this time.
Press any key to continue . . ."

 

Which I fixed to:

 

set JAVA_HOME="C:\Program Files (x86)\Java\jre1.8.0_221"

also:

Java for script.jpg

 

I am now getting the following error:

" -execute
Files was unexpected at this time.
Press any key to continue . . .

 

Message 6 of 21
Certified Master Anaplanner

Re: Script Update Current Date

Would you mind sending the full script (with credentials hidden) you're using and also confirm the set operation line is below: 

 

set Operation=-service "https://api.anaplan.com" -auth "https://auth.anaplan.com" -file "current date.txt" -put "[path including current date.txt]" -import "Current Date from current date.txt" -execute

 

Also to confirm you have set up the import action and named to align to the above?

 

--Jt

Message 7 of 21
New Contributor

Re: Script Update Current Date

Here is my current code:


@echo off

set AnaplanUser="login" (should this be my "Login:Password"?
set WorkspaceId="id"
set ModelId="ID"

set JAVA_HOME="Your Java location"

set JAVA_HOME="C:\Program Files (x86)\Java\jre1.8.0_221"
set Filename="C:\Users\tobrien\Documents\anaplan-connect-1.4.1-1\Current Date.txt"

 

FOR /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set mm=%%a& set dd=%%b& set yyyy=% %c& (if "%%a:~0,1" gtr "9" set mm=%%b& set dd=%%c& set yyyy=%%d))

echo Todays date in Windows format is: %date%

set mydate=%yyyy%-%mm%-%dd%
echo 'Current Date': %mydate%
rem touch Current Date.txt
set snapshot=%mydate%
echo 'Latest Snapshot': %snapshot%

@echo "Current Date"> %FileName%
@echo "%mydate%">> %FileName%

 


set Operation=-service "https://api.anaplan.com" -auth "https://auth.anaplan.com" -file "current date.txt" -put "C:\Users\tobrien\Documents\anaplan-connect-1.4.1-1\Current Date.txt" -import "Current Date from current date.txt" -execute


rem *** End of settings - Do not edit below this line ***
setlocal enableextensions enabledelayedexpansion || exit /b 1
cd %~dp0
if not %AnaplanUser% == "" set Credentials=-user %AnaplanUser%
set Command=.\AnaplanClient.bat %Credentials% -workspace %WorkspaceId% -model %ModelId% %Operation%
@echo %Command%
cmd /c %Command%
pause

Message 8 of 21
Certified Master Anaplanner

Re: Script Update Current Date

Yes, AnaplanUser should be "Email:Password"  assuming you are using basic authentication.   

 

Can you try with that?  I have run the script again on my machine and works fine.  

Message 9 of 21
New Contributor

Re: Script Update Current Date

Ok, so the issue might be I am not using Basic Authentication. I feel like this is a setting in the model.

Message 10 of 21