Azure / logicapps

Azure Logic Apps labs, samples, and tools
MIT License
363 stars 301 forks source link

Bug in logic app #1067

Closed sidndis27 closed 2 months ago

sidndis27 commented 4 months ago

Describe the Bug with repro steps

I have a loop in the logic app to go through a list of users received from an HTTP request I have a variable to save a number of entries in SharePoint set to 0 Inside the loop, I query the SharePoint site to check if the user exists in the SP list for today and count the number of entries returned Save the number of entries in the variable inside the loop Now in the same loop, I check if the number of entries is 0, which means the user does not exist in the SP list and I add the user to the SP list if the number of entries is not equal to 0 I do nothing.

first time in a day when I run the logic It all the users to the SP list the second time when I run it, it never add the missing users to the SP list even though the SP list count for that user returned as 0. Condition failing every time.

What type of Logic App Is this happening in?

Consumption (Portal)

Are you using new designer or old designer

New Designer

Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

No

Workflow JSON

{
  "definition": {
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
    "contentVersion": "1.0.0.0",
    "triggers": {
      "When_a_HTTP_request_is_received": {
        "type": "Request",
        "kind": "Http",
        "inputs": {
          "schema": {
            "items": {
              "properties": {
                "upn": {
                  "type": "string"
                },
                "username": {
                  "type": "string"
                }
              },
              "required": [
                "username",
                "upn"
              ],
              "type": "object"
            },
            "type": "array"
          }
        }
      }
    },
    "actions": {
      "Initialize_variable": {
        "type": "InitializeVariable",
        "inputs": {
          "variables": [
            {
              "name": "todayDate",
              "type": "string",
              "value": "@{formatDateTime(addHours(utcNow(),-7), 'yyyy-MM-dd')}"
            }
          ]
        },
        "runAfter": {}
      },
      "Initialize_isUserExists_-_Int": {
        "type": "InitializeVariable",
        "inputs": {
          "variables": [
            {
              "name": "isUserExists",
              "type": "integer",
              "value": 0
            }
          ]
        },
        "runAfter": {
          "Initialize_variable": [
            "Succeeded"
          ]
        }
      },
      "For_each_-_user": {
        "type": "Foreach",
        "foreach": "@triggerBody()",
        "actions": {
          "Parse_JSON_-_User": {
            "type": "ParseJson",
            "inputs": {
              "content": "@items('For_each_-_user')",
              "schema": {
                "properties": {
                  "upn": {
                    "type": "string"
                  },
                  "username": {
                    "type": "string"
                  }
                },
                "type": "object"
              }
            }
          },
          "Execute_if_user_not_exist": {
            "type": "If",
            "expression": {
              "and": [
                {
                  "equals": [
                    "@variables('isUserExists')",
                    0
                  ]
                }
              ]
            },
            "actions": {
              "Create_item": {
                "type": "ApiConnection",
                "inputs": {
                  "host": {
                    "connection": {
                      "name": "@parameters('$connections')['sharepointonline-1']['connectionId']"
                    }
                  },
                  "method": "post",
                  "body": {
                    "Username": "@body('Parse_JSON_-_User')?['username']",
                    "upn": "@body('Parse_JSON_-_User')?['upn']"
                  },
                  "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://robertallanltd.sharepoint.com/sites/LocationReport'))}/tables/@{encodeURIComponent(encodeURIComponent('9f79618a-4690-4eb1-91d3-9b95cf15a27a'))}/items"
                }
              }
            },
            "else": {
              "actions": {}
            },
            "runAfter": {
              "Set_variable_-_IsUserExist": [
                "Succeeded"
              ]
            }
          },
          "Get_items_-_Check_if_user_already_exists": {
            "type": "ApiConnection",
            "inputs": {
              "host": {
                "connection": {
                  "name": "@parameters('$connections')['sharepointonline-1']['connectionId']"
                }
              },
              "method": "get",
              "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://robertallanltd.sharepoint.com/sites/LocationReport'))}/tables/@{encodeURIComponent(encodeURIComponent('9f79618a-4690-4eb1-91d3-9b95cf15a27a'))}/items",
              "queries": {
                "$filter": "Created ge '@{variables('todayDate')}' and upn eq '@{body('Parse_JSON_-_User')?['upn']}'"
              }
            },
            "runAfter": {
              "Parse_JSON_-_User": [
                "Succeeded"
              ]
            }
          },
          "Set_variable_-_IsUserExist": {
            "type": "SetVariable",
            "inputs": {
              "name": "isUserExists",
              "value": "@length(body('Get_items_-_Check_if_user_already_exists')?['value'])"
            },
            "runAfter": {
              "Get_items_-_Check_if_user_already_exists": [
                "Succeeded"
              ]
            }
          }
        },
        "runAfter": {
          "Initialize_isUserExists_-_Int": [
            "Succeeded"
          ]
        }
      }
    },
    "outputs": {},
    "parameters": {
      "$connections": {
        "type": "Object",
        "defaultValue": {}
      }
    }
  },
  "parameters": {
    "$connections": {
      "value": {
        "sharepointonline-1": {
          "id": "/subscriptions/5ffb16f4-382a-4935-a946-974614d9dd88/providers/Microsoft.Web/locations/canadacentral/managedApis/sharepointonline",
          "connectionId": "/subscriptions/5ffb16f4-382a-4935-a946-974614d9dd88/resourceGroups/RG-DEV/providers/Microsoft.Web/connections/sharepointonline-1",
          "connectionName": "sharepointonline-1"
        }
      }
    }
  }
}

Screenshots or Videos

No response

Browser

Chrome

Additional context

No response

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 45 days with no activity.

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.