LoadRunner User Discussions
cancel

using external js function within trueclient js action script

SOLVED
Go to solution
Highlighted
CR Valued Contributor.
Valued Contributor.

using external js function within trueclient js action script

Dear all,

I'm tryng to script on trueclient web protocol. Since I have common code parts I would lke to create a js library gathering all the common functions and call it within each script. I've created an external file .js I've called the API  TCS.utils.callJSFile to load the library within the js script (Action part) 

TCS.utils.callJSFile({"File Name": "lib.js" });

but I dont know how to call it 

lib.namefunction();  or just function() don't work I get the error " Syntax error in the script:ReferenceError: namefunction is not defined

Thanks

Best Regards

Christian

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
litalr Contributor.
Contributor.
Solution

Re: using external js function within trueclient js action script

Hi,

In order to be able to use the definitions from internal file called by callJSFile you need to define them as members of TCS.

For example:

TCS.Parameter = function (name, type, value, index){
this.name=name;
this.type=type;
this.value=value;
this.index=index;
}

 

and in action.js:

  var par = new TCS.Parameter("name", "type", "value", "index");

 

Thanks,

Lital

5 REPLIES
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Re: using external js function within trueclient js action script

Hello,

Greetings,

Could you share the script that you are trying to modify and import the js so I can check this?

 

Also what results you get by using an evaluate js in TC script and add the code?

https://admhelp.microfocus.com/tc/en/12.56-12.57/Content/TruClient/procedures/_tc_t_insert_js_code.htm

 

jgor2810

Micro Focus Expert
Micro Focus Expert

Re: using external js function within trueclient js action script

Hi,

TCS.utils.callJSFile is supported only in Coded TruClient script, not in a Model based one.

Regards,
Shlomi

CR Valued Contributor.
Valued Contributor.

Re: using external js function within trueclient js action script

Hi,

here is a sample code:

function Parameter(name, type, value, index){
this.name=name;
this.type=type;
this.value=value;
this.index=index;
}

var par=new Parameter("ParamName", "ParamType", "ParamValue",1);

Basically if I put the whole code within the action.js it works fine (compling and running);

If I create a simple file.js including  "Parameter" definition inside it then taking out it from action.js, adding  TCS.utils.callJSFile({"File Name": "file.js"});  and run it. I get an error on the object Parameter which definition is missing

CR Valued Contributor.
Valued Contributor.

Re: using external js function within trueclient js action script

Hi,

yes i'm using full script code: objects and function are defined all together within the action.js. I would like to create some libraries and call them

litalr Contributor.
Contributor.
Solution

Re: using external js function within trueclient js action script

Hi,

In order to be able to use the definitions from internal file called by callJSFile you need to define them as members of TCS.

For example:

TCS.Parameter = function (name, type, value, index){
this.name=name;
this.type=type;
this.value=value;
this.index=index;
}

 

and in action.js:

  var par = new TCS.Parameter("name", "type", "value", "index");

 

Thanks,

Lital