Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Streamlining user types in Qlik Cloud capacity-based subscriptions: Read the Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[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
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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

View solution in original post

11 Replies
Anonymous
Not applicable
Author

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

shong
Anonymous
Not applicable
Author

I saw the documentation but i couldn't find there how to use javascript file?please help me.
Anonymous
Not applicable
Author

Hello
see my screenshot.
Best regards
shong
Anonymous
Not applicable
Author

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?
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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;
}