Kirix Support Forums

Automate functions with Javascript in extension

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

Automate functions with Javascript in extension

Postby cjbaccus on Fri Oct 16, 2009 4:10 pm

I am currently writing an extension that imports a csv file and only brings in a set number of columns from the original csv. I have that function working great with javascript by using an array. One of the columns is a unix timestamp, and I want to make another column and calculate the PST time from the first column. In Kirix I can easily add a calculated field and enter DATE((dateTimeOrigination - 28800)* 1000) to get the UTC offset time, and make the column a datetime type. I want to automate that part with javascript in the extension though, and I am not sure how to do calculated fields within the javascript. Is there any way to solve this in a more automated fashion? Even if we had a macro recorder, it would make things much easier. Please help.
cjbaccus
Registered User
 
Posts: 4
Joined: Thu May 21, 2009 9:21 am

Re: Automate functions with Javascript in extension

Postby Ben on Sat Oct 17, 2009 5:55 am

Hello,

Yes, this is possible. You need to execute an ALTER TABLE command. Here's the approximate code, which I'll write from memory, so if it doesn't work right, let me know.

Code: Select all
var db = HostApp.getDatabase();
db.execute("ALTER TABLE table_name ADD COLUMN calc_field_name NUMERIC(12,0)  AS  DATE((dateTimeOrigination - 28800)* 1000)");


table_name should be the name of your mounted table name, or a file url, e.g. file://c:/path/to/my/file.csv

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

Re: Automate functions with Javascript in extension

Postby cjbaccus on Mon Nov 09, 2009 2:03 pm

That is exactly what I needed!!! Thanks Ben!
--Carl
cjbaccus
Registered User
 
Posts: 4
Joined: Thu May 21, 2009 9:21 am

Return to Strata Help & Feedback