Highlighted
Absent Member.
Absent Member.
402 views

How to use asimple javascript-script to generate an argument to an input field?

Jump to solution

This is supposed to be something really basic, but a search with google and on this forum did neither bring up any explanation nor an example. So this forum is - again - my last hope.

I would like to enter something into a textfield. If this text is hard-coded it is really simple:

 

LR1.png

 

But now I want to name the value to be something different each time. I can use javascript for that, where I replace the "PlainValue" with a "JS" as follows:

LR2.png

with the javascript expression as follows:

"Testtask_" + Math.floor((Math.random() * 1000000) + 1)

So far so good. But now I am trying to replace the single javascript statement with something more complex, like the following:

var currentdate = new Date();
var datetime = currentdate.getFullYear() + (currentdate.getMonth()+1) + currentdate.getDate() + "_"
+ currentdate.getHours()
+ currentdate.getMinutes()
+ currentdate.getSeconds();
return "Testtask-"+datetime;

But now when running this TruClient Script I get the following error:

** 4: Call Function SRG.action_search_task ** was aborted due to an error in the called function

Is the javascript in a wrong format? How to change the javascript-script so that the text-input field is populated with the desired date-output? Is there a way to get a more 'informative' error message?

I want a solution for the case when I have a multi-line javasvript-script! >>> Not just my script in a single line!! << I want a general solution for all the other multiline-cases I might encounter in future!!

0 Likes
1 Solution

Accepted Solutions
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: How to use asimple javascript-script to generate an argument to an input field?

Jump to solution

Hi Alex,

In order to work with multi line editor please click on the JS toggle button, it will open the JavaScript Editor and you will be able to edit your code more easily.

In order to get what you wrote working remove the keyword return. return is required from a function and you code does not include a function.

Let me know if you need further clarification.

Thanks,

Shlomi 

View solution in original post

0 Likes
1 Reply
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: How to use asimple javascript-script to generate an argument to an input field?

Jump to solution

Hi Alex,

In order to work with multi line editor please click on the JS toggle button, it will open the JavaScript Editor and you will be able to edit your code more easily.

In order to get what you wrote working remove the keyword return. return is required from a function and you code does not include a function.

Let me know if you need further clarification.

Thanks,

Shlomi 

View solution in original post

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.