UiPath Documentation
studio
2025.10
false
Studio 用户指南
重要 :
新发布内容的本地化可能需要 1-2 周的时间才能完成。

在编码自动化中使用低代码工作流

在 Studio 的编码自动化中调用低代码工作流,并使用随机值生成场景进行了演示。

本部分教程将向您展示如何在编码自动化中调用低代码工作流。其中涉及的场景包括:

  1. 创建一个名为 Random 的编码工作流(CS 文件),该工作流会在由您提供的最小和最大整数确定的特定范围内生成一个随机值。
  2. 创建一个名为 Increment 的低代码 XAML 工作流,该工作流会为任何给定结果加 1,从而增加接收到的值。
  3. 创建另一个名为 IncrementProxy 的编码工作流(CS 文件),该工作流会从 Random 工作流中获取随机生成的值,并使用 workflows 对象调用此值的 Increment XAML 工作流,然后返回将递增后的结果添加到调用环境。

1. 创建 Random 编码工作流​

  1. 在“文件”组中新建一个编码工作流。
  2. 更改 Execute() 公共类,以接受两个名为 min 和 max 的 int 类型输入参数,并返回 int。输入参数表示生成随机值的边界,而返回参数表示生成的随机值本身。

例如,将 public void Execute() 更改为 public int Execute(int min, int max)。

  1. 使用 new 关键字和 Random() 构造函数创建 Random 类的新对象。
    1. 使用 Random 类实例中的 Next() 方法生成一个介于 min 和 max 之间的随机数。
    2. 将此生成的随机数分配给名为 randomValue 的新变量。
  2. 返回 randomValue 变量。通过将此变量返回给 Execute 方法,您可以在使用 Execute 方法运行的项目中的任意编码工作流中访问 randomValue 变量。
public class Random : CodedWorkflow
    {
        [Workflow]
        public int Execute(int min, int max)
        {
            // Get a random value between min and max
            var randomValue = new Random().Next(min, max);
            
            // Return it to the caller
            return randomValue;
        }
    }
public class Random : CodedWorkflow
    {
        [Workflow]
        public int Execute(int min, int max)
        {
            // Get a random value between min and max
            var randomValue = new Random().Next(min, max);
            
            // Return it to the caller
            return randomValue;
        }
    }

2. 创建 Increment 低代码工作流​

  1. 在“文件”组中,新建工作流。

  2. 创建两个 Int32 类型的参数,名称为“result”和“input.”。将 result 参数的方向设置为“输出”,将 input 参数的方向设置为“输入”。

  3. 添加“赋值”活动。

    1. 在“保存到”字段中,输入result变量。
    2. 在“要保存的值”字段中,添加以下表达式,该表达式会递增input值:input + 1

创建IncrementProxy编码工作流​

  1. 在“文件”组中新建一个编码工作流。
  2. 更改 Execute 类,以采用在本教程的“创建 Random 编码工作流”步骤中创建的 random 变量,并更改该类以返回 int 参数。
  3. 使用 workflows 对象调用 Increment 低代码工作流,向其传递 random Int32 变量,并将输出存储到名为 out_arg 的变量中。
  4. 在输出面板中记录 out_arg 变量。
  5. 将 out_arg 变量返回给 Execute 方法。
public class Workflow : CodedWorkflow
    {
        [Workflow]
        public int Execute(int random)
        {
            // Receive random from the XAML and increment it 
            var out_arg  = workflows.Increment(random);   
            
            // Log the result and return it to the caller
            Log(out_arg.ToString());
            
            // Return the result to the caller
            return out_arg;
        }
    }
public class Workflow : CodedWorkflow
    {
        [Workflow]
        public int Execute(int random)
        {
            // Receive random from the XAML and increment it 
            var out_arg  = workflows.Increment(random);   
            
            // Log the result and return it to the caller
            Log(out_arg.ToString());
            
            // Return the result to the caller
            return out_arg;
        }
    }

结果​

系统将创建三个工作流。已编码的 IncrementProxy 工作流使用 workflows 对象调用低代码 Increment 工作流,并且最终递增的值将返回给调用环境。

  • 1. 创建 Random 编码工作流​
  • 2. 创建 Increment 低代码工作流​
  • 创建IncrementProxy编码工作流​
  • 结果​

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新