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

Best Answer

  • jnoone
    Answer ✓

    Oh i see, can you remove the "set Java_home"  commands (both lines).  You don't need to call these out in the script since you have already added to environmental variables (based on screenshots you sent earlier).

     

    Removing those 2 lines should allow it to work.  

Answers

  • 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

  • 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

  • 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"  ?

  • 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

  • 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 . . .

     

  • 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

  • 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

  • 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.  

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

  • No need to adjust any settings in the model.  If you just add your username:password to the script it will run.  

     

    Let me know if this resolves it for you.  

     

    Jt

  • No need to adjust any settings in the model - this is just to credential using Anaplan Connect API.  If you just add your username:password to the script it will run.  

     

    Let me know if this resolves it for you.  

     

    Jt

  • JT,

     

    If you are ever in Denver, Colorado I owe you a drink (or two). Sadly I am still getting the following error:

     

    Error.jpg

  • Ok, I got rid of that and also updated my JAVA_HOME AND JRE_HOME to the following:Updated Java.jpg

     

    It's say my credentials are invalid; however, I just updated them and it's still saying they are invalid:

     

    incorrect login.jpg

  • It's my password!!!! I use special characters, once I removed ":PASSWORD", the script prompted me to enter my password. After doing so it worked.

  • Great, yep makes sense.  Glad it got resolved.  Have a good one. 

  • Do you know what characters you are unable to use in passwords? I could test all of them but just curiuos if you knew.

  • I don't know that one tbh.  You may want to raise a ticket with support if you are curious, but I'm sure it will prompt you at time of changing.  

  • Hi

    I have found the password requirements from the below Anapedia page.
    https://help.anaplan.com/anapedia/Content/GettingStarted/Changing_your_Password.htm

    Password Reset:
    "Please note that your password must consist of at least 8 characters, should contain both upper and lower case letters, and at least one number."
    ```
    - There isn’t a mention of what special characters can and cannot be used for Anaplan passwords.
    - I would venture to say that the standard special characters contained on a QWERTY keyboard should be allowed for an Anaplan Password
    Hope this helps
    David
  • @tobrien 

    I've checked further and I think £ is the only restriction

    David