robot
2020.10
false
重要 :
请注意此内容已使用机器翻译进行了部分本地化。
UiPath logo, featuring letters U and I in white
不在支持范围内
机器人用户指南
Last updated 2024年7月1日

SDK 规范

您的自定义应用程序或网页中可以包含以下方法和属性:

SDK 规范

初始化

init 方法可选。它会返回 IRobotSDK 实例,使您可以将其存储为变量以供之后使用。
UiPathRobot.init()UiPathRobot.init()

获取流程

Get Process 方法会检索并显示可用流程列表。如果机器人已连接到 Orchestrator,它将从机器人所属的环境和文件夹中检索流程。如果未连接到 Orchestrator,则显示本地流程。
const robot = UiPathRobot.init();
robot.getProcesses()
.then(result => {
  for(let i=0; i<result.length;i++){
    console.log(result[i].name);
  }
}, err => {
  console.log(err);
});const robot = UiPathRobot.init();
robot.getProcesses()
.then(result => {
  for(let i=0; i<result.length;i++){
    console.log(result[i].name);
  }
}, err => {
  console.log(err);
});

开始作业

Start Job 方法通过其 ID 和输入参数(如有)启动流程。
let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
const robot = UiPathRobot.init();
robot.getProcesses()
.then(process => {
  let calculatorProcess = processes.find(p => p.name.includes('Calculator'));
  let job = new job(calculatorProcess.id, arguments);
  robot.startJob(job).then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
const robot = UiPathRobot.init();
robot.getProcesses()
.then(process => {
  let calculatorProcess = processes.find(p => p.name.includes('Calculator'));
  let job = new job(calculatorProcess.id, arguments);
  robot.startJob(job).then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});

启动

On 方法适用于在 SDK 上附加事件处理程序。UiPath JavaScript SDK 随附内置的同意覆盖,每次您的自定义应用程序或网页需要连接到机器人时都会显示。您可以使用自定义处理程序覆盖此同意覆盖。
const robot = UiPathRobot.init();
robot.on('consent-prompt', (consentCode) => {console.log(consentCode)});
robot.on('mising-components', () => {console.log('Missing Components')});const robot = UiPathRobot.init();
robot.on('consent-prompt', (consentCode) => {console.log(consentCode)});
robot.on('mising-components', () => {console.log('Missing Components')});

启动流程

Process Start 方法适用于通过传递输入参数(如果可用)来启动流程。
let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
const robot = UiPathRobot.init();
robot.getProcesses()
.then(process => {
  let process = processes.find(p => p.name.includes('Calculator'));
  process.start(arguments).then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
const robot = UiPathRobot.init();
robot.getProcesses()
.then(process => {
  let process = processes.find(p => p.name.includes('Calculator'));
  process.start(arguments).then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});

流程启动状态

Process Start On Status 方法适用于通过传递回调处理程序来启动流程并附加状态回调。
let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
let globalHandler = (status) => {console.log(status)};
const robot = UiPathRobot.init();
robot.getProcesses()
.then(processes => {
  let statusHandler = (status) => {console.log('Calculator Process Status -' + status)};
  let process = processes.find(p => p.name.includes('Calculator'));
  process.start(arguments)
  .onStatus(globalHandler)
  .onStatus(statusHandler)
  .then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
let globalHandler = (status) => {console.log(status)};
const robot = UiPathRobot.init();
robot.getProcesses()
.then(processes => {
  let statusHandler = (status) => {console.log('Calculator Process Status -' + status)};
  let process = processes.find(p => p.name.includes('Calculator'));
  process.start(arguments)
  .onStatus(globalHandler)
  .onStatus(statusHandler)
  .then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});

停止流程

Stop Process 方法用于停止正在执行或正在运行的机器人流程。返回一个 promise,该 promise 在成功取消正在运行的机器人流程时得到解决。
try {
  const robot = UiPathRobot.init();
  const robotProcessId = 'MyRunningRobot';
  const processes = await robot.getProcesses();
  const myProcess = processes.find(function(process){return process.name.includes(robotProcessId)});
  await robot.stopProcess(myProcess);
  console.log(robotProcessId +' cancelled successfully');
} catch (e) {
  console.log(robotProcessId +' cancellation failed -'+ e);
}try {
  const robot = UiPathRobot.init();
  const robotProcessId = 'MyRunningRobot';
  const processes = await robot.getProcesses();
  const myProcess = processes.find(function(process){return process.name.includes(robotProcessId)});
  await robot.stopProcess(myProcess);
  console.log(robotProcessId +' cancelled successfully');
} catch (e) {
  console.log(robotProcessId +' cancellation failed -'+ e);
}

启动作业

Job On 方法适用于附加事件处理程序,以检索正在进行的流程所处的状态。
let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
const robot = UiPathRobot.init();
robot.getProcesses().then(processes => {
  let calculatorProcess = processes.find(p => p.name.includes('Calculator'));
  let job =new job(calculatorProcess.id, arguments);
  job.on('status', (robotStatus) => {console.log(robotStatus)});
  robot.startJob(job).then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
const robot = UiPathRobot.init();
robot.getProcesses().then(processes => {
  let calculatorProcess = processes.find(p => p.name.includes('Calculator'));
  let job =new job(calculatorProcess.id, arguments);
  job.on('status', (robotStatus) => {console.log(robotStatus)});
  robot.startJob(job).then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});

设置

Settings 方法允许您编辑默认端口号和轮询间隔时间(以毫秒为单位)。
const robot = UiPathRobot.init();
robot.settings.portNumber = 1234;
robot.settings.pollTimeInterval = 1000const robot = UiPathRobot.init();
robot.settings.portNumber = 1234;
robot.settings.pollTimeInterval = 1000

模型定义

设置

class Settings {
    portNumber: number;
    pollTimeInterval: number;
}class Settings {
    portNumber: number;
    pollTimeInterval: number;
}

机器人流程

class RobotProcess {
    id: string;
    name: string;
    constructor(id: string, name: string);
    start: (inArguments?: any) => JobPromise;
}class RobotProcess {
    id: string;
    name: string;
    constructor(id: string, name: string);
    start: (inArguments?: any) => JobPromise;
}

IRobotSDK

interface IRobotSDK {
    settings: Settings;
    getProcesses(): Promise<Array<RobotProcess>>;
    init(): IRobotSDK;
    on(eventName: string, callback: (argument?: any) => void): void;
    startJob(job: Job): Promise<JobResult>;
}interface IRobotSDK {
    settings: Settings;
    getProcesses(): Promise<Array<RobotProcess>>;
    init(): IRobotSDK;
    on(eventName: string, callback: (argument?: any) => void): void;
    startJob(job: Job): Promise<JobResult>;
}

作业结果

/**
 * Job result model containing all output arguments from the process.
 * Empty if there are no out arguments.
 */
class JobResult {
    [Key: string]: any;
}/**
 * Job result model containing all output arguments from the process.
 * Empty if there are no out arguments.
 */
class JobResult {
    [Key: string]: any;
}

作业

class Job {
    processId: string;
    argument?: any;
    jobId: string;
    constructor(processId: string, argument?: any);
    on(eventName: string, eventHanlder: (argument?: any) => void): void;
}class Job {
    processId: string;
    argument?: any;
    jobId: string;
    constructor(processId: string, argument?: any);
    on(eventName: string, eventHanlder: (argument?: any) => void): void;
}

此页面有帮助吗?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath Logo White
信任与安全
© 2005-2024 UiPath。保留所有权利。