- Robot JavaScript SDK
メソッドとプロパティ
以下のメソッドとプロパティは、カスタム アプリケーションまたは Web ページに含めることができます。
Init
init メソッドは任意です。IRobotSDK インスタンスを返します。後で使用するために変数として格納できます。
const robot = UiPathRobot.init();
const robot = UiPathRobot.init();
設定
Settings 型の settings プロパティを使用すると、既定のポート番号とミリ秒単位のポーリング間隔を変更したり、テレメトリ データの送信を無効化したりできます。
const robot = UiPathRobot.init();
robot.settings.portNumber = 1234;
robot.settings.pollTimeInterval = 1000;
robot.settings.disableTelemetry = true;
const robot = UiPathRobot.init();
robot.settings.portNumber = 1234;
robot.settings.pollTimeInterval = 1000;
robot.settings.disableTelemetry = true;
On
on メソッドは、SDK にイベント ハンドラーをアタッチするために使用されます。
利用可能な SDK イベントは consent-prompt、missing-components、および open-uipath-protocol です。
consent-prompt
UIPath JavaScript SDK には、カスタム アプリケーションまたは Web ページがロボットに接続する必要があるたびに表示される同意オーバーレイが組み込まれています。
この同意オーバーレイはカスタム ハンドラーで上書きできます。
const robot = UiPathRobot.init();
robot.on('consent-prompt', consentCode => console.log(consentCode));
const robot = UiPathRobot.init();
robot.on('consent-prompt', consentCode => console.log(consentCode));
missing-components
missing-components イベントは、Robot JS サービスが実行されていない場合に生成されます。この場合、SDK によってエラーが表示されます。これはカスタム ハンドラーで上書きできます。
const robot = UiPathRobot.init();
robot.on('missing-components', () => console.log('Missing Components'));
const robot = UiPathRobot.init();
robot.on('missing-components', () => console.log('Missing Components'));
open-uipath-protocol
同意プロンプトが表示される前に、ブラウザーが uipath-web の URL を関連付けられたアプリケーションで開くことを許可するよう求められる場合があります。
既定では、RobotJS は自動的にこの URL を開こうとしますが、ユーザーはカスタム イベント ハンドラーを提供することでこの動作を上書きできます。
const robot = UiPathRobot.init();
robot.on('open-uipath-protocol', (protocolUrl) => console.log('RobotJS protocol URL: ' + protocolUrl));
const robot = UiPathRobot.init();
robot.on('open-uipath-protocol', (protocolUrl) => console.log('RobotJS protocol URL: ' + protocolUrl));
プロセスを取得
The getProcesses method retrieves the list of available processes. Returns a Promise to an array of RobotProcess objects. If the Robot is connected to Orchestrator, it retrieves the processes from the environment and folder the Robot is a part of. Otherwise, local processes are retrieved.
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
for(let i=0; i<processes.length; i++){
console.log(processes[i].name + " (" + processes[i].description + ") - Id=" + processes[i].id);
}
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
for(let i=0; i<processes.length; i++){
console.log(processes[i].name + " (" + processes[i].description + ") - Id=" + processes[i].id);
}
入力引数の取得スキーマ
インストール済みのプロセスの inputArgumentsSchema プロパティを使用することで、プロセスの入力引数を取得できるようになりました。inputArgumentsSchema プロパティを使用する前に、プロセスをインストールする必要があります。
The installProcess method installs a process and returns a Promise to an object of type InstallProcessResult, which contains an array of InputArgumentSchema objects.
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const installedProcess = await robot.installProcess(processes[0].id);
for(let i=0; i<installedProcess.inputArgumentsSchema.length; i++){
console.log("Argument " + i + ":");
console.log(" name: " + installedProcess.inputArgumentsSchema[i].name)
console.log(" type: " + installedProcess.inputArgumentsSchema[i].type)
console.log(" isRequired: " + installedProcess.inputArgumentsSchema[i].isRequired)
console.log(" hasDefault: " + installedProcess.inputArgumentsSchema[i].hasDefault)
}
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const installedProcess = await robot.installProcess(processes[0].id);
for(let i=0; i<installedProcess.inputArgumentsSchema.length; i++){
console.log("Argument " + i + ":");
console.log(" name: " + installedProcess.inputArgumentsSchema[i].name)
console.log(" type: " + installedProcess.inputArgumentsSchema[i].type)
console.log(" isRequired: " + installedProcess.inputArgumentsSchema[i].isRequired)
console.log(" hasDefault: " + installedProcess.inputArgumentsSchema[i].hasDefault)
}
In TypeScript, the method install of a RobotProcess object can be used to install a process.
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const installedProcess = await myProcess.install();
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const installedProcess = await myProcess.install();
ジョブを開始
The startJob method receives an already created Job and starts it. It returns a Promise to an object of type JobResult, which contains the output arguments.
The createJob method creates a robot Job using the Process Id. It can optionally receive the job input arguments. It returns a Job object.
これまでは、プロセス リストの更新はプロセスの開始前に行われていましたが、v2022.10 からはプロセスの実行と並行して行われるようになりました。つまり、利用可能な更新があるプロセスを実行すると、古いバージョンのプロセスでジョブが実行される可能性があります。
robot = UiPathRobot.init();
processes = await robot.getProcesses();
const calculatorProcess = processes.find(p => p.name.includes('Calculator'));
const arguments = {
"input1" : 23,
"input2" : 42,
"operation" : "add"
};
const job = robot.createJob(calculatorProcess.id, arguments);
const result = await robot.startJob(job);
console.log(result.Sum);
robot = UiPathRobot.init();
processes = await robot.getProcesses();
const calculatorProcess = processes.find(p => p.name.includes('Calculator'));
const arguments = {
"input1" : 23,
"input2" : 42,
"operation" : "add"
};
const job = robot.createJob(calculatorProcess.id, arguments);
const result = await robot.startJob(job);
console.log(result.Sum);
In TypeScript, a Job can be created by using the Job class constructor.
robot = UiPathRobot.init();
processes = await robot.getProcesses();
const calculatorProcess = processes.find(p => p.name.includes('Calculator'));
const arguments = {
"input1" : 23,
"input2" : 42,
"operation" : "add"
};
const job = new Job(calculatorProcess.id, arguments);
const result = await robot.startJob(job);
console.log(result.Sum);
robot = UiPathRobot.init();
processes = await robot.getProcesses();
const calculatorProcess = processes.find(p => p.name.includes('Calculator'));
const arguments = {
"input1" : 23,
"input2" : 42,
"operation" : "add"
};
const job = new Job(calculatorProcess.id, arguments);
const result = await robot.startJob(job);
console.log(result.Sum);
Job On
Job オブジェクトの on メソッドは、ジョブにイベント ハンドラーをアタッチするために使用されます。利用可能なイベントは status と workflow-event です。
ステータス
status イベントは、ジョブの実行中に、ジョブのステータスが変更されるたびに生成されます。
また、[ステータスを報告] アクティビティが実行されるたびに生成されます。
const robot = UiPathRobot.init();
const job = robot.createJob('processId');
job.on('status', robotStatus => console.log(robotStatus));
await robot.startJob(job);
const robot = UiPathRobot.init();
const job = robot.createJob('processId');
job.on('status', robotStatus => console.log(robotStatus));
await robot.startJob(job);
workflow-event
The workflow-event event is raised during the job execution each time an activity that sends a workflow event is executed. It is the support for implementing partial results with the help of send interim results activity. The event handler has an argument of type WorkflowEventData.
const robot = UiPathRobot.init();
const job = robot.createJob('processId');
job.on('workflow-event', e => console.log(e.name));
await robot.startJob(job);
const robot = UiPathRobot.init();
const job = robot.createJob('processId');
job.on('workflow-event', e => console.log(e.name));
await robot.startJob(job);
プロセスを開始
The method start of the object RobotProcess is used to start a process by passing it input arguments, if available.
It returns an object of type JobPromise.
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const arguments = {
"a" : 41,
"b" " 27
};
const result = await myProcess.start(arguments);
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const arguments = {
"a" : 41,
"b" " 27
};
const result = await myProcess.start(arguments);
Process On Status
onStatus メソッドは、ジョブの「status」イベントにイベント ハンドラーをアタッチするために使用されます。
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start().onStatus(status => console.log(status));
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start().onStatus(status => console.log(status));
Process On Workflow Event
onWorkflowEvent メソッドは、ジョブの「workflow-event」イベントにイベント ハンドラーをアタッチするために使用されます。
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start().onWorkflowEvent(e => console.log(e.name));
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start().onWorkflowEvent(e => console.log(e.name));
Stop Process
stopProcess メソッドは、ロボット プロセスの実行を停止するために使用されます。
実行中のロボット プロセスが正常にキャンセルされると解決されるプロミスを返します。
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start();
await robot.stopProcess(myProcess);
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start();
await robot.stopProcess(myProcess);
モデルの定義
IRobotSDK
interface IRobotSDK {
settings: Settings;
getProcesses(): Promise<Array<RobotProcess>>;
init(): IRobotSDK;
on(eventName: string, callback: (argument?: any) => void): void;
startJob(job: Job): Promise<JobResult>;
stopProcess(process: RobotProcess): Promise<void>;
installProcess(processId: string): Promise<InstallProcessResult>;
}
interface IRobotSDK {
settings: Settings;
getProcesses(): Promise<Array<RobotProcess>>;
init(): IRobotSDK;
on(eventName: string, callback: (argument?: any) => void): void;
startJob(job: Job): Promise<JobResult>;
stopProcess(process: RobotProcess): Promise<void>;
installProcess(processId: string): Promise<InstallProcessResult>;
}
設定
class Settings {
portNumber: number;
pollTimeInterval: number;
disableTelemetry: boolean;
}
class Settings {
portNumber: number;
pollTimeInterval: number;
disableTelemetry: boolean;
}
RobotProcess
class RobotProcess {
id: string;
name: string;
description?: string;
start: (inArguments?: any) => JobPromise;
install: () => Promise<InstallProcessResult>;
}
class RobotProcess {
id: string;
name: string;
description?: string;
start: (inArguments?: any) => JobPromise;
install: () => Promise<InstallProcessResult>;
}
InstallProcessResult
class InstallProcessResult {
inputArgumentsSchema: InputArgumentSchema[]
}
class InstallProcessResult {
inputArgumentsSchema: InputArgumentSchema[]
}
InputArgumentSchema
class InputArgumentSchema {
name: string;
type: string;
isRequired: boolean;
hasDefault: boolean;
}
class InputArgumentSchema {
name: string;
type: string;
isRequired: boolean;
hasDefault: boolean;
}
JobPromise
class JobPromise {
onStatus(eventHanlder: (argument?: any) => void): JobPromise;
onWorkflowEvent(eventHanlder: (argument?: any) => void): JobPromise;
}
class JobPromise {
onStatus(eventHanlder: (argument?: any) => void): JobPromise;
onWorkflowEvent(eventHanlder: (argument?: any) => void): JobPromise;
}
Job
class Job {
processId: string;
argument?: any;
jobId: string;
on(eventName: string, eventHanlder: (argument?: any) => void): void;
}
class Job {
processId: string;
argument?: any;
jobId: string;
on(eventName: string, eventHanlder: (argument?: any) => void): void;
}
JobResult
class JobResult {
[Key: string]: any;
}
class JobResult {
[Key: string]: any;
}
WorkflowEventData
class WorkflowEventData {
name: string;
payload: string;
}
class WorkflowEventData {
name: string;
payload: string;
}
- メソッドとプロパティ
- Init
- 設定
- On
- consent-prompt
- missing-components
- open-uipath-protocol
- プロセスを取得
- 入力引数の取得スキーマ
- ジョブを開始
- Job On
- ステータス
- workflow-event
- プロセスを開始
- Process On Status
- Process On Workflow Event
- Stop Process
- モデルの定義
- IRobotSDK
- 設定
- RobotProcess
- InstallProcessResult
- InputArgumentSchema
- JobPromise
- Job
- JobResult
- WorkflowEventData