{ "name": "schedulelogicLastFullWeek", "properties": { "description": "This is half of solution to \nhttps://docs.microsoft.com/en-us/answers/questions/371452/trigger-adf-pipeline-on-second-friday-from-end-of.html?childToView=372604#answer-372604", "activities": [ { "name": "Get Last Day of Month", "description": "Last day of month = Start of next month - 1 day", "type": "SetVariable", "dependsOn": [], "userProperties": [], "typeProperties": { "variableName": "lastDayOfMonth", "value": { "value": "@addDays(startofMonth(getFutureTime(1,'month')),-1)", "type": "Expression" } } }, { "name": "Get Last Week", "description": "Get a weeks worth of dates, subtracting", "type": "ForEach", "dependsOn": [ { "activity": "Get Last Day of Month", "dependencyConditions": [ "Succeeded" ] } ], "userProperties": [], "typeProperties": { "items": { "value": "@range(0,7)", "type": "Expression" }, "activities": [ { "name": "Add To Week", "type": "AppendVariable", "dependsOn": [], "userProperties": [], "typeProperties": { "variableName": "lastWeekofMonth", "value": { "value": "@addDays(variables('lastDayOfMonth'),mul(-1,item()))", "type": "Expression" } } } ] } }, { "name": "Find Fridays", "description": "Friday = 5 in dayOfWeek", "type": "Filter", "dependsOn": [ { "activity": "Get Last Week", "dependencyConditions": [ "Succeeded" ] } ], "userProperties": [], "typeProperties": { "items": { "value": "@variables('lastWeekofMonth')", "type": "Expression" }, "condition": { "value": "@equals(dayOfWeek(item()),5)", "type": "Expression" } } }, { "name": "Max Friday", "description": "Store result of filtered friday. There must only be 1", "type": "SetVariable", "dependsOn": [ { "activity": "Find Fridays", "dependencyConditions": [ "Succeeded" ] } ], "userProperties": [], "typeProperties": { "variableName": "lastFridayOfMonth", "value": { "value": "@activity('Find Fridays').output.Value[0]", "type": "Expression" } } }, { "name": "Is It Day to Run", "description": "Is this day the last Friday - N days or later?\nAND\nIs this day the last Friday or before?", "type": "SetVariable", "dependsOn": [ { "activity": "Max Friday", "dependencyConditions": [ "Succeeded" ] } ], "userProperties": [], "typeProperties": { "variableName": "InRange", "value": { "value": "@if( and(\ngreaterOrEquals(startOfDay(pipeline().TriggerTime), addDays(variables('lastFridayOfMonth'), mul(-1,pipeline().parameters.DaysBeforeFriday)))\n,lessOrEquals(startOfDay(pipeline().TriggerTime),variables('lastFridayOfMonth'))\n), 'Run The PIpeline' , 'Stop')", "type": "Expression" } } } ], "parameters": { "DaysBeforeFriday": { "type": "int", "defaultValue": 3 } }, "variables": { "lastDayOfMonth": { "type": "String" }, "lastWeekofMonth": { "type": "Array" }, "lastFridayOfMonth": { "type": "String" }, "InRange": { "type": "String" } }, "annotations": [] } }