Search code examples
blueprism

How to return an output from javascript function using invoke js in blueprism


I want to read multiple key-value pairs from a webpage and write it to a collection using blueprism. I want to use javascript. I am able to read text from webpage but couldnt understand how to write that data into blueprism data item or a collection.


Solution

  • Blue Prism provides no facility to return data directly from a JavaScript call back into the calling Object. Your best bet is to use a script that generates a hidden input element in the DOM and appends the data you want to exfiltrate:

    var hiddenElement = document.querySelector('#bp-output');
    if (typeof hiddenElement === 'undefined') {
        hiddenElement = document.createElement('input');
        hiddenElement.type = 'hidden';
        hiddenElement.id = 'bp-output';
        document.body.appendChild(hiddenElement);
    }
    hiddenElement.value = /* some functionality to set the value of the newly-created hidden element */;
    

    You'll need to model this element in your object's application modeler, but it's fairly simple to do - you don't need to match on any attributes other than "ID" or "Web ID", and it's a match only to the string bp-output.

    From there, you can use a typical Read stage to read the value out of the value attribute of your element.

    For more complex data structures like Collections, you will have to utilize some serialization trickery to get to where you want to be. For example, if you're trying to read a table into a Collection via JavaScript, your /* functionality to set the value of the newly-created hidden element */ in the example above may need to leverage some code from this SO thread to serialize the table itself to a CSV string. Once you've read the string from the hidden element's value, you could use the CSV-related actions in the vendor-provided Utility - Strings VBO to serialize this to a proper Collection for your use in your Objects/Processes.