0

Hello I try to schedule a logic app to work only between 15-31 every month and I created an array 1. Then I initialize 2 variables (one in which I will store the current day and one that will help me to iterate trough the list at 1. 2. Then I create an for each that goes trough the array with the dates and the dates (value_of_day and utcnow) will be the same 3. But the condition evaluate as false even if they have the same value 4.

Any ideas why if fails (the vcondition is like int(variables('value_of_day')) is equal to int(variables('utcnow')) Thanks for help :)

I tried with different types of conversion like comparing string with string and float with float and is does not work. I am out of ideas

Vonavi
  • 3
  • 1
  • Solved the issue with the help of this post: https://stackoverflow.com/questions/56138487/azure-logic-app-condition-does-not-work-in-loop-if-based-on-changing-values?rq=2 – Vonavi Aug 22 '23 at 13:10

1 Answers1

0

It is not suggested to change values of "Set Variables" in Loops as per Microsoft document as it gives unexpected result.

Snippet from document: enter image description here

I have reproduced in My environment. I was also getting same error. enter image description here

Reason of the error was because value "Value of the day" was fixed.

I have used Compose to get the values of "Value of the day" But in Set Variable connecter values are changing but as you can see below in "Compose" value of "Value of the day" is fixed.

enter image description here

enter image description here

enter image description here

To get the expected result use "current item" instead of Value of day.

int(items('For_each')) is equal to int(variables('utcnow'))

As you can see below:

enter image description here

enter image description here

enter image description here

code view :

   {
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Compose_3": {
                        "inputs": "@variables('Value of day')",
                        "runAfter": {
                            "Set_variable_2": [
                                "Succeeded"
                            ]
                        },
                        "type": "Compose"
                    },
                    "Condition": {
                        "actions": {
                            "Compose": {
                                "inputs": "@items('For_each')",
                                "runAfter": {},
                                "type": "Compose"
                            }
                        },
                        "else": {
                            "actions": {
                                "Compose_2": {
                                    "inputs": "@items('For_each')",
                                    "runAfter": {},
                                    "type": "Compose"
                                }
                            }
                        },
                        "expression": {
                            "and": [
                                {
                                    "equals": [
                                        "@int(items('For_each'))",
                                        "@int(variables('utcnow'))"
                                    ]
                                }
                            ]
                        },
                        "runAfter": {
                            "Compose_3": [
                                "Succeeded"
                            ]
                        },
                        "type": "If"
                    },
                    "Set_variable": {
                        "inputs": {
                            "name": "Value of day",
                            "value": "@{items('For_each')}"
                        },
                        "runAfter": {},
                        "type": "SetVariable"
                    },
                    "Set_variable_2": {
                        "inputs": {
                            "name": "utcnow",
                            "value": "@{formatDateTime(utcNow(),'dd')}"
                        },
                        "runAfter": {
                            "Set_variable": [
                                "Succeeded"
                            ]
                        },
                        "type": "SetVariable"
                    }
                },
                "foreach": "@variables('Set_Period')",
                "runAfter": {
                    "Initialize_variable_2": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_Period_of_time": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Set_Period",
                            "type": "array",
                            "value": [
                                15,
                                16,
                                17,
                                18,
                                19,
                                20,
                                21,
                                22,
                                23,
                                24,
                                25,
                                26,
                                27,
                                28,
                                29,
                                30,
                                31
                            ]
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Value of day",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_Period_of_time": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_variable_2": {
                "inputs": {
                    "variables": [
                        {
                            "name": "utcnow",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "Recurrence": {
                "evaluatedRecurrence": {
                    "frequency": "Month",
                    "interval": 1
                },
                "recurrence": {
                    "frequency": "Month",
                    "interval": 1
                },
                "type": "Recurrence"
            }
        }
    },
    "parameters": {}
}