bk52
May 9, 2019, 12:38pm
1
Hello,
I have a JS code and I want to return value from JS to UIPath. So I tried this
(function() {
var last_page_val=document.getElementById("pageCount").value;
var last_page_count=-1;
if(last_page_val===null || last_page_val===undefined){
last_page_count=-1;
}
else
{
last_page_count=parseInt(last_page_val);
}
return last_page_count;
})();
And it doesn’t works. How can return value from JS?
loginerror
(Maciej Kuźmicz)
May 10, 2019, 10:51am
2
Hi @bk52
Does this topic help?
Here is the solution you are looking for test.zip (2.1 KB)
Just edit the selector of the target for the inject code to a webpage and it will return the innerHTML
Or other topics with examples of the Inject JS usage here .
@bk52 Just change your JavaScript as below.
function getLastPageCount() {
var last_page_val = document.getElementById("pageCount").value;
var last_page_count = -1;
if (last_page_val === null || last_page_val === undefined) {
last_page_count = -1;
} else {
last_page_count = parseInt(last_page_val);
}
return last_page_count;
}
An article about Inject JS Activity
3 Likes
bk52
May 10, 2019, 4:30pm
4
Thank you for your responses.
I solved my problem with return string. I add “toString() ” function and it works. My solution is below
function (e) {
var last_page_val=document.getElementById("pageCount").value;
var last_page_count=10;
if(last_page_val===null || last_page_val===undefined){
last_page_count=-1;
}
else
{
last_page_count=parseInt(last_page_val);
}
console.log("last page count -> " + last_page_count);
return last_page_count.toString();
}
3 Likes
It seems the ScriptOutput
variable type of your Inject JS Script
activity is of type string. You don’t need to do that conversion if the variable type was integer. So if you set the type of variable last_page_count
to Int32
, you can remove the conversion you do in the JavaScript.
bk52
May 10, 2019, 5:15pm
6
@KannanSuresh
I try it with simply like that but it didn’t work.
I created a varible “outPut ” as Int32
Then I return 1 from JS.
function (e) {
return 1;
}
If I select “ContinueOnError ” property false it gives me an error “is not a valid for Int32 ”
If I select “ContinueOnError ” property true it doesn’t return 1
Only If I return this parameters as a string It works successfully.
P.S. UiPath 2019.4.2 Community Edition
It seems you are right. The documentation also says the same.
Output
ScriptOutput - String result returned from JavaScript code.
The UiPath Documentation Portal - the home of all our valuable information. Find here everything you need to guide you in your automation journey in the UiPath ecosystem, from complex installation guides to quick tutorials, to practical business...
@bk52 Did you try this on a browser other than Internet Explorer? If so I think this is some issue.
I tried the codes with Internet Explorer and it works fine. But when tried with Chrome, I need to return a string from the JavaScript for it to work. This is really weird.
1 Like
I have raised a bug in the forum related to this.
Scenario:
I am trying to inject same JavaScript to both Internet Explorer and Chrome. Script is a simple one that returns number value 1. See the script below.
function return1(){
return 1;
}
Same activity works fine with IE and results in an error when tried with chrome. See the details below.
Steps to reproduce:
Start a new process.
Create a variable jsReturnValueFromIE of type Int32.
Create a variable jsReturnValueFromChrome of type Int32.
Add open browser activity and choose IE as …
1 Like
bk52
May 13, 2019, 9:10am
10
@KannanSuresh
I tried it with Chrome 74.0.3729.131
system
(system)
Closed
May 16, 2019, 9:10am
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.