COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: dsmuker on 27 Jan 2020 07:20:20 PM

Title: Rename Files using Cognos
Post by: dsmuker on 27 Jan 2020 07:20:20 PM
I am using Cognos Event studio to schedule reports to write output CSV files at file location. Apparently, the output file has suffix "en-gb". is it possible to rename the files using cognos.
for the moment i have created a Batch script to rename the files. Is there a way to run the batch script using cognos event studio?
I cannot use it using stored procedure as DBAs will not let me to export it to cognos.

Thanks
Gary
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 28 Jan 2020 01:00:50 PM
research on CM.OUTPUTSCRIPT

not sure though if this feature is still in v11
Title: Re: Rename Files using Cognos
Post by: dougp on 28 Jan 2020 07:06:57 PM
CM.OUTPUTSCRIPT is in the documentation for CA11.  What I don't know is what Cognos wants for a path.  Does it want something like e:\foldername\script.bat, or file://\\servername\sharename\script.bat?  Are there examples available.  What I have found online in the last couple hours has been useless.
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 29 Jan 2020 07:32:00 AM
its been a while since i've done this... your server is windows right? why don't you experiment first with a simple batch file?

for example copy x.txt y.txt
then try the each path see which one works?

i could experiment as well from my end but it will take time. i recon you will can get the answer before i can get back to you
Title: Re: Rename Files using Cognos
Post by: dougp on 29 Jan 2020 10:12:41 AM
Uhmm... Yeah...
I already have a script and I have set the value of the property.  The script isn't being called.  It's not a permissions problem.  As I stated, I don't see any examples of what, exactly, to enter for the value of the CM.OUTPUTSCRIPT variable.
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 29 Jan 2020 10:59:14 AM
just curious... have you set the "save the report to file system" property to "yes"?
Title: Re: Rename Files using Cognos
Post by: dougp on 29 Jan 2020 11:00:53 AM
Yes.  Reports get saved to the location I expect.  The script just doesn't get called.
Title: Re: Rename Files using Cognos
Post by: Penny on 03 Feb 2020 02:09:43 PM
If the account running the scheduled report has its language preference set to en-gb, then shouldn't the prefix on the filename be removed?
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 11 Feb 2020 08:29:39 AM
ok took me a while to find time to restart the server services and experiment on this.

i encountered the issue wherein files gets saved but batch file seems it did not run. batch file looks like this:

copy x.txt y.txt

then i changed it to explicit directory definition

copy c:\temp\x.txt c:\temp\y.txt

it worked.
Title: Re: Rename Files using Cognos
Post by: dougp on 11 Feb 2020 10:51:44 AM
Did it not run, or did it not work?
What happens if you change the file like this to make it start in the correct directory and perform logging?


@echo OFF
@rem --------------------------------------------------------------
@rem
@rem --------------------------------------------------------------
setlocal

@rem store the drive and path of this file in a variable
set dirname=%~dp0
@rem cd to the directory containing this file
pushd %dirname%

@rem do stuff
echo log entry 1 >> log.txt
copy x.txt y.txt


@rem cd back to where we started
popd


endlocal
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 12 Feb 2020 07:06:58 AM
it did run for me.

why don't you try running a simple batch file first like i did?
Title: Re: Rename Files using Cognos
Post by: dougp on 12 Feb 2020 06:43:40 PM
You said it didn't run.

Quotei encountered the issue wherein files gets saved but batch file seems it did not run. batch file looks like this:

copy x.txt y.txt

Now you are saying it did run?  Which is it?
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 13 Feb 2020 07:04:41 AM
Quote from: Francis aka khayman on 11 Feb 2020 08:29:39 AM
then i changed it to explicit directory definition

copy c:\temp\x.txt c:\temp\y.txt

it worked.
Title: Re: Rename Files using Cognos
Post by: dougp on 13 Feb 2020 10:19:58 AM
So when the bat file was

copy x.txt y.txt

did it not run or did it not work?
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 13 Feb 2020 11:26:41 AM
i would say it worked in the sense that the batch file ran.

it looked for the file x.txt but it did not find it in the folder where it was looking for. so no file was copied.

when the file location was explicitly stated, it was able to find the file and copy it.
Title: Re: Rename Files using Cognos
Post by: dougp on 13 Feb 2020 12:12:40 PM
Again, if it did nothing how do you know the bat file ran?  Were the additional lines in the bat file that performed logging?

Maybe there is a problem with my configuration:
QuoteCM.OUTPUTSCRIPT is in the documentation for CA11.  What I don't know is what Cognos wants for a path.  Does it want something like e:\foldername\script.bat, or file://\\servername\sharename\script.bat?  Are there examples available.  What I have found online in the last couple hours has been useless.

What did you enter for the value of CM.OUTPUTSCRIPT?
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 13 Feb 2020 12:38:46 PM
Quote from: dougp on 13 Feb 2020 12:12:40 PM
Again, if it did nothing how do you know the bat file ran?  Were the additional lines in the bat file that performed logging?
because when i changed the batch file to explicitly specify the folder location, it ran fine.

Quote from: dougp on 13 Feb 2020 12:12:40 PM
Maybe there is a problem with my configuration:
What did you enter for the value of CM.OUTPUTSCRIPT?
e:\temp\a.bat    ;D 8)
Title: Re: Rename Files using Cognos
Post by: dougp on 13 Feb 2020 02:12:57 PM
Hmmm... That's what I'm using.

The documentation states that CM.OutPutLocation is mandatory if you want to save report output files in IBM Cognos software.  Did you enter that parameter?  Is it the same thing that appears in Cognos Configuration > Actions | Global Configuration > Archive Location File System Root?
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 13 Feb 2020 02:30:04 PM
ok i think we are getting somewhere. i encountered this in the past...

there are now 2 ways of saving a report...

1. the old way is cm.outputlocation

2. the new way is defining a file output location in Dispatchers and Services.

when you use cm.outputscript, you have to use #1. cm.outputscript will not work if with #2

The value I defined in Archive Location File System Root is:

file:///temp

and yes it also works when i use way #2.



Title: Re: Rename Files using Cognos
Post by: dougp on 13 Feb 2020 02:57:11 PM
I'm confused.  Aren't #1 and #2 the same thing?

The documentation (https://www.ibm.com/support/knowledgecenter/en/SSEP7J_11.0.0/com.ibm.swg.ba.cognos.ug_cra.doc/t_asg_steps_setting_file_location.html) says to:
Open Admin Console
Configuration
Dispatchers and Services
{click on the dispatcher}
Content Manager Service > Properties
Settings
Advanced Settings > Edit...
Create a parameter named CM.OutPutLocation with a value that is the path to the directory (like e:\ReportOutput)
Create a parameter named CM.OutputScript with a value that is the path to the batch script (like e:\scripts\DoSomething.bat)

How do...
Cognos Configuration > Local Configuration > Environment > Data Access > Content Manager > Save report outputs to a file system?
...and...
Cognos Configuration > Actions | Global Configuration > Archive Location File System Root
...play into this?  Does having them set create a conflict with CM.OutputScript?

Are the parameter names case-sensitive?  Is the documentation correct?  (OutPutLocation or OutputLocation, OutputScript or OutPutScript)
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 13 Feb 2020 03:20:05 PM
they are different. first way, this is the old one dating back to reportnet is to use cm.outputlocation and the documentation seems accurate.


the second way is to define the file System Location... you can do that using...

Ibm Cognos Administration > Configuration > Dispatchers and Services

at the upper right there are some icons... new folder, cut, paste,...etc third from the right is "Define File System Location"

you define a location and give it a name for example "Location 123"

then for example if you schedule a report to run... one of the Delivery options is to Save report as an external file...

Under that, you can find "Location 123" from the Location choices
Title: Re: Rename Files using Cognos
Post by: dougp on 13 Feb 2020 03:39:48 PM
Apparently, I've been using the second way.  It requires...
Cognos Configuration > Local Configuration > Environment > Data Access > Content Manager > Save report outputs to a file system? = True
...and...
Cognos Configuration > Actions | Global Configuration > Archive Location File System Root = file://\\servername\ReportOutput

Then I...
. create subfolders in ReportOutput
. go into "Define File System Location" and alias those folders and set permissions


So now I have added CM.OutPutLocation and CM.OutputScript to the Content Manager Service advanced settings, but they don't appear to do anything.


Is there a conflict?
Does this mean that if I want to run a script, I need to roll back those updates to Cognos Configuration, and I lose the ability to have subfolders with different write permissions?
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 13 Feb 2020 03:50:31 PM
ok more info...

the second way is usually used in scheduling and running batches

the first way is when you run a report in the background and saved excel, html, etc is produced. you will get a saved html in run history as well as in the location you defined in CM.OUTPUTLOCATION. at the same time CM.OUTPUTSCRIPT is triggered when defined.
Title: Re: Rename Files using Cognos
Post by: dougp on 13 Feb 2020 04:38:38 PM
I have been running this way for years.  It works for schedules and agents, as well as Run as... | Run in background...

But...

Now I wonder about the quality of the documentation and the knowledge of the consultants that set up my Cognos environment.

Pages 77-79 of the IBM Cognos Analytics Version 11.0 Administration and Security Guide (https://www.ibm.com/support/knowledgecenter/SSEP7J_11.0.0/com.ibm.swg.ba.cognos.ug_cra.doc/ug_cra.pdf) include information about this.

Saving report output files outside of IBM Cognos software
Report output files can be saved to a file system outside of IBM Cognos software. Users can choose which
output files to save.
  talks about Archive Location File System Root and creating the aliases by using Define File System Locations
  writes messy file names and provides no scripting options


Saving report output files in IBM Cognos Software
Users can save copies of report output files in IBM Cognos software. All report output files are saved to a
location specified in Content Manager.
  uses Save report outputs to a file system = true
  this mentions CM.OutPutLocation and CM.OutputScript


The two things appear to be unrelated.  The first allows reports that are scheduled or run in the background to be sent to a directory on the file system.  The second causes every saved "version" of a report to be also saved to the file system.  Apparently the only reason I have not been duplicating all of my saved reports is I did not have CM.OutPutLocation set.  (And I'm happy about that.  Running out of drive space is not fun.)  If that's true, it seems like I don't need Save report outputs to a file system = true.

Bummer.  I was hoping I could write a script to strip off the "_en_us" from all of the file names of my report outputs and delete all of the XML files.
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 14 Feb 2020 07:32:09 AM
yup they are unrelated in the sense that they are independent of each other.

but it seems to me you can still write that script. you will just have to deal with duplicate saved reports. the easiest way is to include a delete in your batch file.
Title: Re: Rename Files using Cognos
Post by: dougp on 18 Feb 2020 10:17:17 AM
Nope.  The script gets called when a copy of a report output (version) are created on the file system.  It does not run when the report is sent to the file system using Run as... or a schedule and the option "Save report as external file" is used (and output is not saved as a version).
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 18 Feb 2020 11:06:36 AM
i haven't tested but if you schedule the report you can select 2 kinds of deliveries: Save report as external file and save report.

i could be wrong here but i think if you select both, it will save the report 2x as well as run the script. through the script you can then rename the file created in save report as external file provided the output folder is fixed, then delete the duplicate files.
Title: Re: Rename Files using Cognos
Post by: dougp on 18 Feb 2020 03:35:17 PM
I think I finally understand how this works.  It seems less configurable, but the script picks up the rest of the configuration...

My current way (using Archive Location File System Root):

To replicate the functionality using CM.OutPutLocation and CM.OutputScript:


So the second option seems like more coding, but far more flexible.  It must be a .bat file, but that can call anything (PowerShell, Windows Scripting Host, executable) to do the actual work, so batch programming isn't even needed.

Both would not be needed.  If I implement CM.Output*, I'll probably clear the Archive Location File System Root box so that "Save report as an external file" disappears from the list of delivery options.

Thanks for sticking with me, Francis.  This was very helpful.
Title: Re: Rename Files using Cognos
Post by: Francis aka khayman on 19 Feb 2020 08:48:27 AM
glad to help