Kirix Support Forums
Automate functions with Javascript in extension
3 posts
• Page 1 of 1
Automate functions with Javascript in extension
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
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.
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
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
Kirix Support Team
-
Ben - Kirix Support Team
- Posts: 525
- Joined: Mon Dec 19, 2005 6:29 am
Re: Automate functions with Javascript in extension
That is exactly what I needed!!! Thanks Ben!
--Carl
--Carl
- cjbaccus
- Registered User
- Posts: 4
- Joined: Thu May 21, 2009 9:21 am
3 posts
· Page 1 of 1
Return to Strata Help & Feedback