Developer Guide

Developer Guide :construction_worker_woman:

To get started, make sure you have community 20.2 or later (or have downloaded the JS Enterprise Add-on). Also, make sure that you have some processes published and available on your local robot and that you can see them from the Agent Desktop (Robot Tray).

This user guide provides samples in JavaScript using ES6 Async-Await patterns and arrow functions. It also assumes that you’re using the provided code from within an async funciton.
Self invoking anonymous async function:

(async () => {
    // Your code here...
})()

UiPathRobot.js uses Promises and the npm package provides TypeScript bindings - so this isn’t the only way to use the SDK!

Including the SDK

In order to use the SDK you’ll have to include it on a hosted webpage. You cannot use the SDK from the local filesystem (ie: file:///C:/path/to/index.html), but you can use localhost for development purposes (static server one-liners). There are a few options for including the SDK:

CDN - before the closing of your </ body> tag, include:

<script src="//download.uipath.com/js/1.1.1/UiPathRobot.js"></script>

Alternatively you can download the SDK and host it yourself.

NPM - Compatible with Webpack/Babel

npm install --save @uipath/robot

Then import UiPathRobot:

import {UiPathRobot} from '@uipath/robot';

Process list

Getting the process list is easy, just use .getProcesses(), which will return an array of available processes on your local robot.

const processes = await UiPathRobot.getProcesses()

Now processes is a list of avialalble processes on your local Robot.

Starting a process

To start a processes, you can call .start() on any of the processes returned by the .getProcesses() function. A call to .start() returns a Job Promise. In this example we start the first available process and pass in a single input argument. The key name that you use in this object should correspond to an exact string match for an ‘In’ argument for your process. Keys names that don’t correspond to an argument will be ignored. In this case we’re just using a string as the input value, but for complex arguments types (eg: DataTable) you can use JavaScript objects.

const job = processes[0].start({ SomeKey: "Custom Value" })

Monitor process status

The Job object represents an instance of a process and exposes process status via the onStatus function. This allows you to let users know what the process is doing, while it executes.
Custom Status Messages
When creating your process, use the ‘Report Status’ activity. When that activity executes in your process, the value passed into it will be injected into the callback you provide.

job.onStatus(status => { console.log(`Status: ${status}`) })

Visualize results

After a job is complete you can retrieve all of the process output arguments by name

const results = await job
console.log(results['SomeOutput'], results['AnotherOutput'])

Error handling

If at any time (while getting processes, running a process, etc) there is an error, UiPathRobot.js will throw an exception. To catch this exception you can wrap your code in a try/catch

try{
    const processes = await robot.getProcesses()
    const sample = processes[0]
    const job = sample.start({ NumberToAdd: 6 })
    job.onStatus(message => { console.log(`${sample.name}: ${message}`) })
    const results = await job
    console.log(`Sum: ${results.Sum}`)
} catch(e) { 
    // If anything goes wrong
    console.log(`Exception: ${e}`)
}

Other useful shortcuts

A few other helpful code snippets!

// Get process by ID
const byID = processes.find(p => p.id == "c9973f8d-a46b-41cd-8436-f411cdba3355")
// Get process by Name
const byName = processes.find(p => p.name.includes("MyProcess_env"))

End to end

All together now :notes:

(async () => {
    try{
        // Get the list of processes
        const processes = await UiPathRobot.getProcesses()
        
        // Find a specific process by name
        const sample = processes.find(p => p.name.includes("MyProcess_env"))
        
        // Start the process (creates a job)
        const job = sample.start({ NumberToAdd: 0 })
        
        // When the job status changes, log it to the console
        job.onStatus(status => {console.log(`Status: ${status}`)})
        
        // After the job completes log process results to the console
        const results = await job
        console.log(results)
        
    } catch(e) { 
        // Handle any errors
        console.error(e) 
    }
})()

Feedback

What else would you like to see? Here at UiPath we thrive on feedback and would love to hear any comments/issues/ideas that you have.

Did you build something cool with UiPathRobot.js and want to share? Reach out to @evan.cohen on the forum, we would love to highlight your work for the rest of the community to benefit.

6 Likes

Would like to see more around “discovery”, meaning for example, the ability to pull and identify Arguments & Parameters associated with a given Process.

1 Like

Thanks for the feedback @rstaylor62! We’ll definitely look into this.

@evan.cohen hi…I have a question can the sample code(Index.html) run without locahost?