[resolved] How to use javascript file?

One Star

[resolved] How to use javascript file?

Hi
I am having javascript file and i need to use javascript file in my application.How can i use my javascript file by using talend tool?Could anyone please guide me?
Thanks
Jyothsna.E

Accepted Solutions
Community Manager

Re: [resolved] How to use javascript file?

Hello All
I show you how to run a javascript in tSystem component and pass parameters to javascript.
function.js:
var args = WScript.Arguments;
try{
if (args.length == 0) {
throw "No Argument";
} else {
WScript.Echo( "The first param is: "+args(0));
WScript.Echo( "The second param is: "+args(1));
}
}catch(e) {
WScript.Echo(e);
}

Command:
"cmd /c cscript function.js \"Hello\" \"World\""

Result:
Starting job forum6262 at 11:03 21/04/2009.
Microsoft (R) Windows Script Host Version 5.7
Copyright(C) Microsoft Corporation 1996-2001?All rights reserved?
The first param is: Hello
The second param is: World
Job forum6262 ended at 11:03 21/04/2009.

Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

All Replies
Community Manager

Re: [resolved] How to use javascript file?

Hello
Using the tSystem component to run the javascript file, see the user documentation and search it on forum.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] How to use javascript file?

I saw the documentation but i couldn't find there how to use javascript file?please help me.
Community Manager

Re: [resolved] How to use javascript file?

Hello
see my screenshot.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] How to use javascript file?

In your screen shot,in Command textfield i need to mention my javascript file name like "cmd /c functions.js".Am i right?
And How can i pass the parameters from flat file to javascript function?
One Star

Re: [resolved] How to use javascript file?

Hello,
tRhino is the implementation of JavaScript on Talend that enable user to scripting on Talend:
*Allows direct scripting of Java
*A JavaScript shell for executing JavaScript scripts
*A JavaScript compiler to transform JavaScript source files into Java class files
http://www.talendforge.org/exchange/tos/extension_view.php?eid=124
For more information about Rhino see here : http://www.mozilla.org/rhino/
Regards Mbaroudi
Community Manager

Re: [resolved] How to use javascript file?

Hello All
I show you how to run a javascript in tSystem component and pass parameters to javascript.
function.js:
var args = WScript.Arguments;
try{
if (args.length == 0) {
throw "No Argument";
} else {
WScript.Echo( "The first param is: "+args(0));
WScript.Echo( "The second param is: "+args(1));
}
}catch(e) {
WScript.Echo(e);
}

Command:
"cmd /c cscript function.js \"Hello\" \"World\""

Result:
Starting job forum6262 at 11:03 21/04/2009.
Microsoft (R) Windows Script Host Version 5.7
Copyright(C) Microsoft Corporation 1996-2001?All rights reserved?
The first param is: Hello
The second param is: World
Job forum6262 ended at 11:03 21/04/2009.

Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Community Manager

Re: [resolved] How to use javascript file?

Hello Jyothsna.E
And How can i pass the parameters from flat file to javascript function?

Here is a job shows you how to achieve that.
function.js:
var args = WScript.Arguments;
try{
if (args.length == 0) {
throw "No Argument";
} else {
WScript.Echo( "The first param is: "+args(0));
WScript.Echo( "The second param is: "+args(1));
}
}catch(e) {
WScript.Echo(e);
}

in.csv:

a1;a2
b1;b2

command:
"cmd /c cscript function.js "+(String)globalMap.get("row1.param1")+" "+(String)globalMap.get("row1.param2")

Result:
Starting job forum6262 at 11:17 21/04/2009.
Microsoft (R) Windows Script Host Version 5.7
Copyright(C) Microsoft Corporation 1996-2001?All rights reserved?
The first param is: a1
The second param is: a2
Microsoft (R) Windows Script Host Version 5.7
Copyright(C) Microsoft Corporation 1996-2001?All rights reserved?
The first param is: b1
The second param is: b2
Job forum6262 ended at 11:17 21/04/2009.

Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] How to use javascript file?

Hi shong thank you for your reply and i understood how to pass the parameters & your code.Let me try with my javascript and i will let you know if i face any problem.

Thanks
Jyothsna.E
One Star

Re: [resolved] How to use javascript file?

Hi this is my javascript function.In my javascript function i am returning the value and i need to get the value & i need to pass this value as a input to some other column in a table.How can i do it?

function EventID(SPECIAL8,SPECIAL13,SPECIAL14 ,SPECIAL15,SPECIAL16)
{
var allevent="";
if(SPECIAL8 !="" )
{
allevent=allevent+SPECIAL8+"";
}
else if(SPECIAL13 != "" )
{
allevent=allevent+""+SPECIAL13;
}
else if(SPECIAL14 != "" )
{
allevent=allevent+""+SPECIAL14;
}
else if(SPECIAL15 != "" )
{
allevent=allevent+""+SPECIAL15;
}
else if(SPECIAL16 != "" )
{
allevent=allevent+""+SPECIAL16;
}

return allevent;
}
Community Manager

Re: [resolved] How to use javascript file?

Hello Jyothsna.E
I show you how to get the return value from javascript.
function.js:
function test(){
var value = "shong";
WScript.Echo("return value:"+value); //In your case, you need add one line: WScript.Echo("return value:"+allevent);
}
test();

Console:
Starting job forum6262_tsystem_javascript at 20:39 24/04/2009.
Microsoft (R) Windows Script Host Version 5.6
copyright (C) Microsoft Corporation 1996-2001?
return value:shong
================================
shong
Job forum6262_tsystem_javascript ended at 20:39 24/04/2009.

Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] How to use javascript file?

Hi everybody,
I am working on a similar use case.
I want to read a variable amount of text files and parse some of the text contents into JSON-syntax, using a Javascript with everything embedded in talend.
My specific question is: How to call my function in talend and how to get my script, respectively my function, to use the text input coming from the talend input-component?
Thanks in advance!

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Download