Skip to main content

Assign Target Time

This workflow is included in the Local Government Essentials - Task Target Time package.

Description​

Assigns a target time for a Task based on Task Priority.

Properties​

This workflow has the following properties.

PropertyValue
NameAssign Target Time
Codeworkflows_cYPCalculateTargetTimeFromTaskPriority_893f68cf86b38b2faabce6de
TypeWorkflow
ContextPackage
EnabledYes
TagsCauseway
Log retention30 days

Trigger​

The system triggers this workflow when items of the design below are created or edited. Where attributes are listed, an edit to anything else is ignored.

PropertyValue
Workflow typeEvent workflow
Applies toTasks
EventsCreate, Edit
CollectionsLive
Attributes listened forattributes_tasksRaisedTime  (Raised Time)
attributes_tasksPriority  (Priority)
Output modeManyItems  (Runs once for all items)
Can be triggered by other workflowsYes (indirectly, via item changes)

Actions​

This workflow runs 4 actions, in the order shown in this simplified diagram. Every action's full settings are in the configuration below.

Configuration​

The full configuration of this workflow, including every action's parameters.

Show configuration (322 lines)
{
"trigger": {
"dodiCode": "designInterfaces_tasks",
"collections": [
"Live"
],
"events": [
"Create",
"Edit"
],
"outputMode": "ManyItems",
"canBeTriggeredByWorkflows": true,
"attributesListeningFor": [
"attributes_tasksRaisedTime",
"attributes_tasksPriority"
]
},
"actions": [
{
"actionId": "8c4e38eb7fa5e272f5e8753a",
"designCode": "designs_workflowFilterAction",
"description": "Filter Tasks that have priority set",
"parameters": [
{
"attribute": {
"attributeCode": "attributes_workflowFilterActionsAqsQuery",
"value": {
"type": "Query",
"properties": {
"dodiCode": "designInterfaces_tasks",
"collectionCode": "Live",
"attributes": [
"attributes_itemsTitle",
"attributes_itemsSubtitle"
]
},
"children": [
{
"type": "And",
"children": [
{
"type": "Exists",
"children": [
{
"type": "Attribute",
"properties": {
"attributeCode": "attributes_tasksPriority"
}
}
]
},
{
"type": "Equals",
"children": [
{
"type": "Attribute",
"properties": {
"attributeCode": "attributes_taskStatusTypesTreatAs",
"path": "root.attributes_tasksStatus.attributes_taskStatusesStatusType"
}
},
{
"type": "String",
"properties": {
"value": [
"Open"
]
}
}
]
}
]
}
]
},
"attributeType": "Aqs"
}
}
],
"variables": [],
"actions": [
{
"actionId": "834986ace2097ef287718568",
"description": "get task priority",
"designCode": "designs_workflowRelationAction",
"parameters": [
{
"attribute": {
"attributeCode": "attributes_workflowRelationActionsAqsPath",
"value": "root.attributes_tasksPriority",
"attributeType": "Link"
}
}
],
"actions": [],
"variables": []
},
{
"actionId": "834dce9e46963f6740f92850",
"designCode": "designs_workflowQueryAction",
"description": "gets bank holidays",
"parameters": [
{
"attribute": {
"attributeCode": "attributes_workflowQueryActionsSingleInstance",
"value": true,
"attributeType": "Boolean"
}
},
{
"attribute": {
"attributeCode": "attributes_workflowQueryActionsAqsQuery",
"value": {
"type": "Query",
"properties": {
"parameters": [
{
"name": "raisedTime",
"type": "Date"
}
],
"attributes": [
"attributes_itemsTitle",
"attributes_itemsSubtitle"
],
"collectionCode": "Live",
"dodiCode": "designs_holidays"
},
"children": [
{
"type": "GreaterThan",
"properties": {
"inclusive": true
},
"children": [
{
"type": "Attribute",
"properties": {
"attributeCode": "attributes_holidaysStartDate"
}
},
{
"type": "Date",
"properties": {
"parameterName": "raisedTime"
}
}
]
}
]
},
"attributeType": "Aqs"
}
}
],
"variables": [
{
"name": "raisedDateTime",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_tasksRaisedTime"
}
},
"attributeType": "DateTime"
},
{
"name": "raisedTime",
"value": {
"script": "Date(raisedDateTime)"
},
"attributeType": "Date"
}
],
"actions": []
},
{
"actionId": "8e2fb2a2b95a1d53d42e6323",
"description": "[WFC] Target time based on priority",
"designCode": "designs_workflowEditItemAction",
"parameters": [
{
"attributeCode": "attributes_tasksTargetTime",
"value": {
"script": "offsetHours == 0 && offsetDays ==0 ? job_target_time : finalTargetTime"
},
"attributeType": "DateTime"
}
],
"variables": [
{
"name": "finalTargetTime",
"value": {
"script": "onWorkingDaysFromPriority == true ? new_job_target_time : nonWorkingDayTargetTime"
}
},
{
"name": "priorityItemId",
"value": {
"outputAction": "834986ace2097ef287718568",
"outputMode": "Input",
"itemValue": {
"property": "ItemId"
}
},
"attributeType": "Link"
},
{
"name": "bankHolidays",
"value": {
"outputAction": "834dce9e46963f6740f92850",
"itemValue": {
"attributeCode": "attributes_holidaysStartDate"
},
"outputMode": "All"
}
},
{
"name": "job_target_time",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_tasksTargetTime"
}
}
},
{
"name": "job_raised_time",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_tasksRaisedTime"
}
}
},
{
"name": "offsetDaysFromPriority",
"value": {
"outputAction": "834986ace2097ef287718568",
"itemValue": {
"attributeCode": "attributes_taskPriorityListTaskPriorityDays_8c78910839579f5fe10aa099"
},
"outputMode": "Input"
}
},
{
"name": "onWorkingDaysFromPriority",
"value": {
"outputAction": "834986ace2097ef287718568",
"itemValue": {
"attributeCode": "attributes_tasksPriorityListWorkingDaysHours_82d2235720646bba8f9304db"
},
"outputMode": "Input"
}
},
{
"name": "businessStartHourFromPriority",
"value": {
"outputAction": "834986ace2097ef287718568",
"itemValue": {
"attributeCode": "attributes_tasksPriorityListWorkingHoursStart_85f2e1798c45255b4952909e"
},
"outputMode": "Input"
}
},
{
"name": "businessEndHourFromPriority",
"value": {
"outputAction": "834986ace2097ef287718568",
"itemValue": {
"attributeCode": "attributes_tasksPriorityListWorkingHoursEnd_8e84ae2d5226200f41df5209"
},
"outputMode": "Input"
}
},
{
"name": "offsetHoursFromPriority",
"value": {
"outputAction": "834986ace2097ef287718568",
"itemValue": {
"attributeCode": "attributes_taskPriorityListTaskPriorityHours_8a304a6661abab82c263374c"
},
"outputMode": "Input"
}
},
{
"name": "offsetHours",
"value": {
"script": "offsetHoursFromPriority ?? 0"
}
},
{
"name": "offsetDays",
"value": {
"script": "offsetDaysFromPriority ?? 0"
}
},
{
"name": "addOffsetDays",
"value": {
"script": "offsetDays != null ? job_raised_time.Value.AddDays((int)offsetDays.Value) : job_raised_time"
}
},
{
"name": "nonWorkingDayTargetTime",
"value": {
"script": "offsetHours != null ? addOffsetDays.Value.AddHours((int)offsetHours.Value) : addOffsetDays"
}
},
{
"name": "new_job_target_time",
"value": {
"script": "var workingDays = (int)offsetDays.Value + 1; var businessStartHour = businessStartHourFromPriority ?? 8; var businessEndHour = businessEndHourFromPriority ?? 17; var nowUTC= Now; var nowLocal=Local(nowUTC); var ts = nowLocal-nowUTC; var utcOffset=ts.Value.Hours; var businessStartHourUTC = businessStartHour - utcOffset; var businessEndHourUTC = businessEndHour - utcOffset; DateTime new_job_target_time = new DateTime(); DateTime new_new_job_target_time = new DateTime(); var movedRaisedTime = job_raised_time.Value; var daysToCheck = Enumerable.Range(0,1825); IEnumerable<DateTime> validWorkingDays = new List<DateTime>(); var holidays = Variables.bankHolidays.AllValues.Values.Select(x => x.SingleValue).ToList(); if(movedRaisedTime.DayOfWeek == DayOfWeek.Saturday){movedRaisedTime = movedRaisedTime.Date.AddDays(2).AddHours(businessStartHourUTC);} else if(movedRaisedTime.DayOfWeek == DayOfWeek.Sunday){movedRaisedTime = movedRaisedTime.Date.AddDays(1).AddHours(businessStartHourUTC);}else if(movedRaisedTime>movedRaisedTime.Date.AddHours(businessEndHourUTC) && movedRaisedTime.DayOfWeek== DayOfWeek.Friday){movedRaisedTime = movedRaisedTime.Date.AddDays(3).AddHours(businessStartHourUTC);} else if(movedRaisedTime>movedRaisedTime.Date.AddHours(businessEndHourUTC)){movedRaisedTime = movedRaisedTime.Date.AddDays(1).AddHours(businessStartHourUTC);} else if(movedRaisedTime < movedRaisedTime.Date.AddHours(businessStartHourUTC)){movedRaisedTime = movedRaisedTime.Date.AddHours(businessStartHourUTC);} if (movedRaisedTime==movedRaisedTime.Date.AddHours(businessStartHourUTC) && (int)offsetHours.Value==0){validWorkingDays = daysToCheck.Where(d=>movedRaisedTime.Date.AddDays(d-1).AddHours(businessEndHourUTC).DayOfWeek !=DayOfWeek.Saturday && movedRaisedTime.Date.AddDays(d-1).AddHours(businessEndHourUTC).DayOfWeek !=DayOfWeek.Sunday && !holidays.Contains(Date(movedRaisedTime.Date.AddDays(d-1).AddHours(businessEndHourUTC)))).Select(d => movedRaisedTime.Date.AddDays(d-1).AddHours(businessEndHourUTC));}else{validWorkingDays = daysToCheck.Where(d=>movedRaisedTime.AddDays(d).DayOfWeek !=DayOfWeek.Saturday && movedRaisedTime.AddDays(d).DayOfWeek !=DayOfWeek.Sunday && !holidays.Contains( Date(movedRaisedTime.AddDays(d)))).Select(d => movedRaisedTime.AddDays(d));}; new_job_target_time = validWorkingDays.ElementAt((int)workingDays -1);if ((int)offsetHours.Value>0){new_job_target_time=new_job_target_time.AddHours((int)offsetHours.Value);}if (new_job_target_time>new_job_target_time.Date.AddHours(businessEndHourUTC)){new_job_target_time=new_job_target_time.Date.AddDays(1).AddHours(businessStartHourUTC + (new_job_target_time - new_job_target_time.Date.AddHours(businessEndHourUTC)).TotalHours);}{validWorkingDays = daysToCheck.Where(d=>new_job_target_time.AddDays(d).DayOfWeek !=DayOfWeek.Saturday && new_job_target_time.AddDays(d).DayOfWeek !=DayOfWeek.Sunday && !holidays.Contains( Date(new_job_target_time.AddDays(d)))).Select(d => new_job_target_time.AddDays(d));};new_job_target_time = validWorkingDays.ElementAt(0);return new_job_target_time;"
}
}
],
"actions": []
}
]
}
]
}