Compartir a través de


Ejemplos de código de operaciones de datos para Azure Logic Apps

Se aplica a: Azure Logic Apps (consumo + estándar)

Estos son ejemplos de código de definiciones de acción de operaciones de datos del artículo Realización de operaciones de datos. Puede usar estos ejemplos para probarlos con la definición de flujo de trabajo subyacente de su propia aplicación lógica, su suscripción de Azure o sus conexiones de API. Solo tiene que copiar y pegar estas definiciones de acción en el editor de vista de código para la definición de flujo de trabajo de su aplicación lógica y luego modificar las definiciones para su flujo de trabajo específico.

Según los estándares de notación de objetos JavaScript (JSON), estas definiciones de acción aparecen en orden alfabético. Sin embargo, en el Diseñador de aplicación lógica, cada definición aparece en la secuencia correcta dentro del flujo de trabajo porque la propiedad runAfter de cada definición de acción especifica el orden de ejecución.

Compose

Para probar la acción de ejemplo Redactar, estas son las definiciones de acción que puede usar:

"actions": {
  "Compose": {
    "type": "Compose",
    "inputs": {
      "age": "@variables('ageVar')",
      "fullName": "@{variables('lastNameVar')}, @{variables('firstNameVar')}"
    },
    "runAfter": {
      "Initialize_variable_-_ageVar": [
          "Succeeded"
      ]
    }
  },
  "Initialize_variable_-_ageVar": {
    "type": "InitializeVariable",
    "inputs": {
      "variables": [
        {
          "name": "ageVar",
          "type": "Integer",
          "value": 35
        }
      ]
    },
    "runAfter": {
      "Initialize_variable_-_lastNameVar": [
        "Succeeded"
      ]
    }
  },
  "Initialize_variable_-_firstNameVar": {
    "type": "InitializeVariable",
    "inputs": {
      "variables": [
        {
          "name": "firstNameVar",
          "type": "String",
          "value": "Sophie "
        }
      ]
    },
    "runAfter": {}
  },
  "Initialize_variable_-_lastNameVar": {
    "type": "InitializeVariable",
    "inputs": {
      "variables": [
        {
          "name": "lastNameVar",
          "type": "String",
          "value": "Owen"
        }
      ]
    },
    "runAfter": {
      "Initialize_variable_-_firstNameVar": [
        "Succeeded"
      ]
    }
  }
},

Crear tabla CSV

Para probar la acción de ejemplo Crear tabla CSV, estas son las definiciones de acción que puede usar:

"actions": {
   "Create_CSV_table": {
      "type": "Table",     
      "inputs": {
         "format": "CSV",
         "from": "@variables('myJSONArray')"
      },
      "runAfter": {
         "Initialize_variable_-_JSON_array": [
            "Succeeded"
         ]
      }
   },
   "Initialize_variable_-_JSON_array": {
      "type": "InitializeVariable",
      "inputs": {
         "variables": [ 
            {
               "name": "myJSONArray",
               "type": "Array",
                  "value": [
                     {
                        "Description": "Apples",
                        "Product_ID": 1
                     },
                     {
                        "Description": "Oranges",
                        "Product_ID": 2
                     }
                  ]
            }
         ]
      },
      "runAfter": {}
   }
},

Crear tabla HTML

Para probar la acción de ejemplo Crear tabla HTML, estas son las definiciones de acción que puede usar:

"actions": {
   "Create_HTML_table": {
      "type": "Table",     
      "inputs": {
         "format": "HTML",
         "from": "@variables('myJSONArray')"
      },
      "runAfter": {
         "Initialize_variable_-_JSON_array": [
            "Succeeded"
         ]
      }
   },
   "Initialize_variable_-_JSON_array": {
      "type": "InitializeVariable",
      "inputs": {
         "variables": [ 
            {
               "name": "myJSONArray",
               "type": "Array",
                  "value": [
                     {
                        "Description": "Apples",
                        "Product_ID": 1
                     },
                     {
                        "Description": "Oranges",
                        "Product_ID": 2
                     }
                  ]
            }
         ]
      },
      "runAfter": {}
   }
},

Filter array

Para probar la acción de ejemplo Filtrar matriz, estas son las definiciones de acción que puede usar:

"actions": {
   "Filter_array": {
      "type": "Query",
      "inputs": {
         "from": "@variables('myIntegerArray')",
         "where": "@greater(item(), 1)"
      },
      "runAfter": {
         "Initialize_variable_-_integer_array": [
            "Succeeded"
         ]
      }
   },
   "Initialize_variable_-_integer_array": {
      "type": "InitializeVariable",
      "inputs": {
         "variables": [ 
            {
               "name": "myIntegerArray",
               "type": "Array",
               "value": [
                  1,
                  2,
                  3,
                  4
               ]
            }
         ]
      },
      "runAfter": {}
   }
},

Join

Para probar la acción de ejemplo Combinar, estas son las definiciones de acción que puede usar:

"actions": {
   "Initialize_variable_-_integer_array": {
      "type": "InitializeVariable",
      "inputs": {
         "variables": [ 
            {
               "name": "myIntegerArray",
               "type": "Array",
               "value": [
                  1,
                  2,
                  3,
                  4
               ]
            }
         ]
      },
      "runAfter": {}
   },
   "Join": {
      "type": "Join",
      "inputs": {
         "from": "@variables('myIntegerArray')",
         "joinWith": ":"
      },
      "runAfter": {
         "Initialize_variable_-_integer_array": [
             "Succeeded"
         ]
      }
   }
},

Parse JSON

Para probar la acción de ejemplo Análisis del archivo JSON, estas son las definiciones de acción que puede usar:

"actions": {
   "Initialize_variable_-_JSON_object": {
      "type": "InitializeVariable",
      "inputs": {
         "variables": [
            {
               "name": "myJSONObject",
               "type": "Object",
               "value": {
                  "Member": {
                     "Email": "Sophie.Owen@contoso.com",
                     "FirstName": "Sophie",
                     "LastName": "Owen"
                  }
               }
            }
         ]
      },
      "runAfter": {}
   },
   "Parse_JSON": {
      "type": "ParseJson",
      "inputs": {
         "content": "@variables('myJSONObject')",
         "schema": {
            "type": "object",
            "properties": {
               "Member": {
                  "type": "object",
                  "properties": {
                     "Email": {
                        "type": "string"
                     },
                     "FirstName": {
                        "type": "string"
                     },
                     "LastName": {
                        "type": "string"
                     }
                  }
               }
            }
         }
      },
      "runAfter": {
         "Initialize_variable_-_JSON_object": [
            "Succeeded"
         ]
      }
   }
},

Seleccionar

Para probar el ejemplo de acción Seleccionar, las definiciones de acción siguientes crean una matriz de objetos JSON a partir de una matriz de enteros:

"actions": {
   "Initialize_variable_-_integer_array": {
      "type": "InitializeVariable",
      "inputs": {
         "variables": [ 
            {
               "name": "myIntegerArray",
               "type": "Array",
               "value": [
                  1,
                  2,
                  3,
                  4
               ]
            }
         ]
      },
      "runAfter": {}
   },
   "Select": {
      "type": "Select",
      "inputs": {
         "from": "@variables('myIntegerArray')",
         "select": {
            "Product_ID": "@item()"
         }
      },
      "runAfter": {
         "Initialize_variable_-_integer_array": [
           "Succeeded"
         ]
      }
   }
},

En el ejemplo siguiente se muestran las definiciones de acción que crean una matriz de cadenas a partir de una matriz de objetos JSON, pero para esta tarea, junto al cuadro Asignar , cambie al modo de texto (Icon for text mode.) en el diseñador o use el editor de vistas de código en su lugar:

"actions": {
   "Initialize_variable_-_object_array": {
      "type": "InitializeVariable",
      "inputs": {
         "variables": [ 
            {
               "name": "myObjectArray",
               "type": "Array",
               "value": [
                  {"Val":"1", "Txt":"One"},
                  {"Val":"2", "Txt":"Two"},
                  {"Val":"4", "Txt":"Four"},
                  {"Val":"10", "Txt":"Ten"}
               ]
            }
         ]
      },
      "runAfter": {}
   },
   "Select": {
      "type": "Select",
      "inputs": {
         "from": "@body('myObjectArray')?['value']",
         "select": "@{item()?['Txt']}"
      },
      "runAfter": {
         "Initialize_variable_-_object_array": [
           "Succeeded"
         ]
      }
   }
},

Pasos siguientes