Page 1 of 1

ASCII output file that doesnt overwrite

Posted: Fri Mar 24, 2017 7:58 pm
by Jefflinde
I have a current process that loads salary and has checks in place to write an exception file if there are issues with the account and cost center for the person being loaded. the file is written with the below code. PathName is a variable that we are pulling from the systemprocessinfo cube. the issue i am having is if i run the process twice, the second run overwrites and exceptions from the first. How do i get a time stamp on there? I have a variable called timestamp that is using the NOW function but when i try to append that to the file name nothing works.

IF(DIMIX('ApprovalHierarchy', CostCenter)=0);
ErrorFlag=1;
ErrorMsg='Cost Center Does Not Exist';
ASCIIOutput(PathName|'SalaryLoadExistingEmployee.txt',CostCenter,ErrorMsg);
ITEMSKIP;

Variables from Prolog
PathName=CellGetS('SystemProcessInfo','1','Process');
timestamp = TIME;

Re: ASCII output file that doesnt overwrite

Posted: Fri Mar 24, 2017 8:24 pm
by tomok
It's pretty simple, just change your filename to append the time, formatted as a string, to it. I'm not going to write your code for you. Look up the TI function called FormatDate. You can use that, in conjunction with NOW, to get a date string the way you want it, then just append it to 'SalaryLoadExistingEmployee' and then '.txt' for your filename.

Re: ASCII output file that doesnt overwrite

Posted: Sat Mar 25, 2017 1:49 am
by Wim Gielis
Or, as an alternative to FormatDate, consider the Timst function. That's not difficult at all.

Re: ASCII output file that doesnt overwrite

Posted: Sun Mar 26, 2017 10:20 pm
by Wim Gielis
Here is code for you.

Code: Select all

# Result: 2017-03-26 21:03:19

vNow = Timst( Now, '\Y-\m-\d \h:\i:\s' );
AsciiOutput( 'test.txt', vNow );


# Result: 2017-03-26 21:03:19

q = NewDateFormatter( '' );
vNow = FormatDate( Now, 'y-LL-dd HH:mm:ss', q );

AsciiOutput( 'test.txt', vNow );


# Result: 20170326 210319

q = NewDateFormatter( '' );
vNow = FormatDate( Now, 'yLLdd HHmmss', q );

AsciiOutput( 'test.txt', vNow );

I do like the NewDateFormatter approach as it is so flexible.
You have to call that function only once, at the beginning of the Prolog tab for example.
It has 5 arguments, of which the first HAS to be provided (although you can leave it empty),
the other 4 arguments are optional and can be skipped (knowing the default values you can end up with).

Important notions about NewDateFormatter:
1.
The line of code must be executed BEFORE the first FormatDate or ParseDate function !
If the NewDateFormatter value is initialized for the first time as the last argument in either function, it does not work

2.
Functions like NOW give a result that is to be interpreted with UTC times:
http://www.tm1forum.com/viewtopic.php?t=10196
so the parameter <TimeZone> should be left empty (or be 'Etc/UTC') unless some times from other timezones are to be interpreted

Re: ASCII output file that doesnt overwrite

Posted: Mon Mar 27, 2017 2:22 pm
by Jefflinde
This is perfect. thank you all of you for the great advice. i am pretty new at TM1 if you could not tell from question. I am slowing figuring out all the quirks.

thanks again everyone.

Re: ASCII output file that doesnt overwrite

Posted: Tue Mar 28, 2017 2:49 pm
by Jefflinde
Ok, one more question. is there a process that creates a new file instead of adding to an existing one. Or maybe i am doing it wrong which is very likely. My process is now erring out because the file name with date can not be found.

thank you

Jeff

Re: ASCII output file that doesnt overwrite

Posted: Tue Mar 28, 2017 3:09 pm
by Steve Rowe
This most often happens because the file you are writing to is open in another application (excel). When its says it can't find it what it means is I can't write to this location.

Re: ASCII output file that doesnt overwrite

Posted: Tue Mar 28, 2017 5:06 pm
by tomok
Jefflinde wrote:Ok, one more question. is there a process that creates a new file instead of adding to an existing one. Or maybe i am doing it wrong which is very likely. My process is now erring out because the file name with date can not be found.
Have you verified that the file name you are creating is valid? How about the path, is it valid? If TM1 says the file can not be found that likely means because it could not create it. Probably because 1) you didn't specify a valid path, 2) the account the TM1 service runs under does not have windows security rights to the folder you specified, or 3) the file name you created is not a valid Windows file name.

Re: ASCII output file that doesnt overwrite

Posted: Tue Mar 28, 2017 6:45 pm
by Jefflinde
Thanks again everyone. i had a semi colon in the file name that i could not see until i dumped the string into a text editor. so i deleted and retyped it. All is now right in my little world.