3

Could someone tell me how can I, in Blue Prism, get data into Data Item from web page using action in Navigate stage Invoke JavaScript or Insert JavaSript fragment?

For example I'm using function:

function myFunction()
{var x=document.getelementById("demo").innerHTML;
return x;}

and I'd like to get this return value into Data item in Blue Prism for processing.

Marek Stejskal
  • 2,698
  • 1
  • 20
  • 30

1 Answers1

5

Unfortunately there is no quick way of doing that, however there is a very easy workaround.

You need to create a "bridge" between JavaScript and Blue Prism, something both technologies can interact with. In this case the simplest bridge is an HTML textbox.

JavaScript can create and write to a temporary, invisible textbox on the page and Blue Prism can spy it and read from it.

I use the following script to add the textbox and/or clear its value...

if (document.getElementById("JSOutput") == null){
    // Add invisible textbox
    var body = document.getElementsByTagName("body")[0];
    var text = document.createElement("input");
    text.id = "JSOutput";
    text.style.display = "none";
    body.insertBefore(text, body.firstChild);
}
else  {
    // Clear invisible textbox
    document.getElementById("JSOutput").innerText = "";
}

... and then the following script to write something to it.

var output = document.getElementById("JSOutput");
output.innerText = "Hello World!"

You can then spy or manually add the element into application modeler:

enter image description here

Marek Stejskal
  • 2,698
  • 1
  • 20
  • 30
  • hey there. this does not seem to work as-is for chrome. the ability to read from the text box once created only yields no result. is there something to add on to this to make it work in chrome? – Dexter Whelan Oct 19 '21 at 16:29
  • @DexterWhelan I don't see why it would be any different from IE, but I don't have access to BP at the moment to check. I suggest using chrome dev tools/page inspector to see what works and what did not, tweaking the script if necessary (making it visible, for debugging). – Marek Stejskal Oct 19 '21 at 21:23