javascriptblueprismrpa

Get data from web page using JavaScript in BluePrism


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.


Solution

  • 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