Kirix Support Forums

Converting data within a script

Please post any help questions, requests or other feedback here.

Converting data within a script

Postby SLSJax on Tue May 10, 2011 1:26 pm

Is there anyway to script a commonly used conversion?

That is, I have a specific sql file that is created that I will often convert to an XLS. Is there any way to do this as a script, or will I have to manually go through the export or Save External process every time?

Thanks,
SLS
SLSJax
Registered User
 
Posts: 11
Joined: Fri Mar 18, 2011 10:40 am

Re: Converting data within a script

Postby Ben on Tue May 10, 2011 4:37 pm

Yes, you can do what you describe. Follow these steps

1) Create a connection to your database in your project via File->Create Connection...
2) Rename your new connection to something short, like "mnt" (stands for 'mount')
3) Create a script with the following lines:

Code: Select all
    HostServices.data.copyFile('/mnt/table', '/destination_table');
    HostApp.refresh()


4) Once you've verified that running the script above actually creates a table named destination_table, you can proceed by adding a final line to your script:

Code: Select all
    HostServices.data.exportData( '/destination_table', "c:\\users\\myuser\\file.xls");


You'll notice that the backslashes are doubled. This is because the backslash is also a Javascript escape character.

All the best,
Ben
Ben Williams
Kirix Support Team
User avatar
Ben
Kirix Support Team
 
Posts: 525
Joined: Mon Dec 19, 2005 6:29 am

Re: Converting data within a script

Postby SLSJax on Tue May 10, 2011 9:18 pm

Ben,

Thanks for the prompt response.

I've been unable to get this to work. Here's the actual code I am using:

Code: Select all
      HostServices.data.copyFile('/ClaimTankSQL/cmsupload', '/cmsup');
      HostApp.refresh();
      HostServices.data.exportData('/cmsup', 'p:\\2010\\Tools\\file.xls');


The first statement works - it creats a database called cmsup off of the root. The second statement doesn't seem to work, as nothing is written out to p:\2010\Tools (I've tried with both single quotes and double quotes).

Have I missed something?

(BTW, I also noticed that HostServices seems to be undocumented - I can't find it in the API)
SLSJax
Registered User
 
Posts: 11
Joined: Fri Mar 18, 2011 10:40 am

Return to Strata Help & Feedback