UiPath Documentation
functions
latest
false
函数用户指南
  • 概述
    • 关于函数
  • Python 函数
    • 入门指南
    • 构建 Python 函数
    • 访问平台服务
    • Resource bindings
    • Declare a resource binding
    • Call an Integration Service activity
    • 追踪和可观察性
    • 测试和调试
  • 部署并运行

Declare a resource binding

Declare an Orchestrator or Integration Service resource in bindings.json, verify it resolves during a local run, and make it remappable across tenants.

bindings.json is maintained by hand: uipath init creates the file with the required structure when it is absent, and leaves an existing file untouched. Declare a binding for every platform resource your function reaches, so the resource can be remapped when the package runs in another tenant. For the resolution mechanism behind this, see Resource bindings.

先决条件

  • A Python function project created with uipath new.
  • An authenticated session, established with uipath auth.
  • The resource already exists in the tenant you develop against.
  • The UiPath CLI (uip) is installed, for the connection lookup in step 1.

Declare a connection binding

  1. Retrieve the connection id from Integration Service:

    uip is connections list uipath-microsoft-outlook365
    uip is connections list uipath-microsoft-outlook365
    
  2. Open bindings.json at the project root.

  3. Add an entry to the resources array, using the connection id for both key and ConnectionId.defaultValue:

    {
      "resource": "connection",
      "key": "<connection-id>",
      "value": {
        "ConnectionId": {
          "defaultValue": "<connection-id>",
          "isExpression": false,
          "displayName": "Microsoft Outlook 365 Connection"
        },
        "Connector": {
          "defaultValue": "uipath-microsoft-outlook365",
          "isExpression": false,
          "displayName": "Connector"
        }
      },
      "metadata": {
        "Connector": "uipath-microsoft-outlook365",
        "UseConnectionService": "True",
        "BindingsVersion": "2.2"
      }
    }
    {
      "resource": "connection",
      "key": "<connection-id>",
      "value": {
        "ConnectionId": {
          "defaultValue": "<connection-id>",
          "isExpression": false,
          "displayName": "Microsoft Outlook 365 Connection"
        },
        "Connector": {
          "defaultValue": "uipath-microsoft-outlook365",
          "isExpression": false,
          "displayName": "Connector"
        }
      },
      "metadata": {
        "Connector": "uipath-microsoft-outlook365",
        "UseConnectionService": "True",
        "BindingsVersion": "2.2"
      }
    }
    
  4. Declare the same id as a module-level constant in your function, and pass it to the SDK call:

    OUTLOOK_CONNECTION_KEY = "<connection-id>"
    
    conn = sdk.connections.retrieve(OUTLOOK_CONNECTION_KEY)
    OUTLOOK_CONNECTION_KEY = "<connection-id>"
    
    conn = sdk.connections.retrieve(OUTLOOK_CONNECTION_KEY)
    
  5. Run the function locally:

    uipath run main -f input.json
    uipath run main -f input.json
    

结果

The run log contains one line per declared binding:

No resource overwrite matched for connection key='connection.<connection-id>' on retrieve
No resource overwrite matched for connection key='connection.<connection-id>' on retrieve

This line confirms the override lookup ran and fell back to the design-time id, which is the expected outcome locally because no tenant mapping exists. If the line names a different id than the one in bindings.json, the code constant and the binding disagree.

备注:

Declaring bindings for other resource types follows the same pattern with a different value shape. Assets, buckets, queues, processes, apps, and indexes use name and folderPath instead of ConnectionId, and their key joins the two with a dot.

Make the binding remappable across tenants

  1. Register the function project in a solution:

    uip solution project add ./my-solution/my-function
    uip solution project add ./my-solution/my-function
    
  2. Sync the solution's resource list from the project's declared bindings:

    uip solution resource refresh
    uip solution resource refresh
    
  3. Review the resulting resource list:

    uip solution resource list --source local
    uip solution resource list --source local
    

结果

Every declared binding appears in the solution's local resource list. Deployment maps each entry to a resource in the target tenant, so the same package runs against that tenant's own connection. For packaging and publishing the solution, see uip solution pack.

警告:

A binding that is not mapped in the target tenant does not fail the job. The call falls back to the design-time identifier, so verify that every binding appears in the target tenant's resource mapping before promoting a solution.

后续步骤

  • 先决条件
  • Declare a connection binding
  • 结果
  • Make the binding remappable across tenants
  • 结果
  • 后续步骤

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新