Highlighted
Respected Contributor.. Respected Contributor..
Respected Contributor..
1133 views

Adding Javascript function file gives errors

Jump to solution

Hi

I want to use a javascript function to generate a client side id. So I added a test,js file in the Extra files of my HTTP protocol script, and added a line with

#include "test.js"

to the globals.h file. I also enabled javascript for the test in the run settings.

Then I tried it by adding this very simple function(see end of the post) to the test,js file. But when I compile this, it gives the error : syntax error; found `myFunction' expecting `;'

Clearly it does not like the function file, but I dion't see hwat is the problem. Mind, I am not calling the function from anuwhere in the test at this point, so that can not be the issue...Anybody some advice? I am not a vey experienced javascript programmer, so maybe I am forgetting something obvious, but I would like to learn what.

 function myFunction(a, b) {
    return a * b;
}

0 Likes
1 Solution

Accepted Solutions
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: Adding Javascript function file gives errors

Jump to solution

Hello KajFeis,

You can run JavaScript code within a C language Web-HTTP/HTML script, using the web_js_run API.

The error you receive means that the C compiler is unable to compile the file content.
Javascript code cannot be compiled by the the C compiler and does not need compilation anyway.
Bottom line: there is no need to '#include' the .js file in you globals.h file.

Other steps you took are a great start (configuration, extra files).
Now just add a call to your code using web_js_run.

Edo

View solution in original post

5 Replies
Highlighted
Super Contributor.
Super Contributor.

Re: Adding Javascript function file gives errors

Jump to solution

Hi KajFeis,
According to my understanding, when you first create a Web project, it's C based project. If you want to change it to Javascript based project, please follow below steps:

1. create a new web project. (at this time, the project is C based)

2. go to "Recording Options" from the "Record" file menu, change the language option to "Javascript"record_option.png

 3. Do a simple recording, if you don't want any steps, you can just record a "about:blank" page then stop. After the recording, your project will be turned to a "Javascript based" project, like belowjs_pro.png

4. then you can create your test.js with your function under the Extra Files, and require your js file in the globals.js:

 

require.png

 

5. After that, you can call your javascript function from the Web script's action view:

 

action.png

 

Hope this is what you want! 

-Penn

 

 

 

 

Highlighted
Respected Contributor.. Respected Contributor..
Respected Contributor..

Re: Adding Javascript function file gives errors

Jump to solution

Hi Penn,

I was hoping that I could use a javascript library inside my C-based script...the documentation gave me the idea that this was possible. And it would be a very nice feature, given that string manipulations etc are much easier in javascript than C....

But if i understand you corectly, then this is only possible if I start with Javascript as my scripting language from the creation of the script. .

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: Adding Javascript function file gives errors

Jump to solution

Hello KajFeis,

You can run JavaScript code within a C language Web-HTTP/HTML script, using the web_js_run API.

The error you receive means that the C compiler is unable to compile the file content.
Javascript code cannot be compiled by the the C compiler and does not need compilation anyway.
Bottom line: there is no need to '#include' the .js file in you globals.h file.

Other steps you took are a great start (configuration, extra files).
Now just add a call to your code using web_js_run.

Edo

View solution in original post

Highlighted
Super Contributor.
Super Contributor.

Re: Adding Javascript function file gives errors

Jump to solution

Hi KajFeis,

my first post will make you create a pure javascript- based web project, if you want C base project, you need to use the web_js_run API as Edo's suggestion, a sample for you, hope it can help!

 web_js_run.png

 

 -Penn

0 Likes
Highlighted
Respected Contributor.. Respected Contributor..
Respected Contributor..

Re: Adding Javascript function file gives errors

Jump to solution

Yes! I removed the #include and it compiles beautifull! Thanks to you both for the answers, I always wanted to have some easier way to do certain things like string anipulation that are very difficult in C compared to Javascript, so I look forward to diving into this!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.