- Joined
- Oct 21, 2020
- Messages
- 678
- Reaction score
- 524
I do know, that there are some smart people here 
Need some help with a script to set a single Department into Holliday mode.
There is a working demo script from 3CX, that will set ALL Departments at the same time:
https://www.3cx.com/blog/call-flow-scripts/force-pbx-hours/
However... how to set a single Department?
Below is the code that I did create... non working
The problem is to find the instance by name, and than use that instance to change the state or something like that (do not know) or use the Department number??
Any help would be great
Paulo
Need some help with a script to set a single Department into Holliday mode.
There is a working demo script from 3CX, that will set ALL Departments at the same time:
https://www.3cx.com/blog/call-flow-scripts/force-pbx-hours/
However... how to set a single Department?
Below is the code that I did create... non working
The problem is to find the instance by name, and than use that instance to change the state or something like that (do not know) or use the Department number??
C#:
#nullable disable
using CallFlow;
using System;
using System.Threading.Tasks;
using TCX.Configuration;
using System.Linq;
using CallFlow.CFD;
using System.Collections.Generic;
namespace dummy
{
public class ForceBreak : ScriptBase<ICall>
{
public override async Task<bool> StartAsync()
{
var ps = MyCall.PS as PhoneSystem;
if(MyCall.Caller.DN is Extension && MyCall.ReferredByDN is null)
{
string targetDepartmentNumber = "023";
//force office hours until midnight
string targetDepartmentName = "MyDepartment";
var targetDepartment = ps.GetAll<Group>()
.Where(x => x.Name.Equals(targetDepartmentName, StringComparison.OrdinalIgnoreCase))
.Extract(x => x.AllowCallService)
.FirstOrDefault();
if (targetDepartment != null)
{
try
{
//force hiliday until midnight
var groupCurrentTime = targetDepartment.Now(out var utc, out var timezone, out var groupmode);
targetDepartment.OverrideExpiresAt = (groupCurrentTime + TimeSpan.FromDays(1)).Date;
targetDepartment.CurrentGroupHours = GroupHoursMode.ForceHoliday;
MyCall.Info($"{targetDepartment.Name} set to '{targetDepartment.CurrentGroupHours}' until {targetDepartment.OverrideExpiresAt}, timezone={timezone}, groupmode={groupmode}");
// Save the single department
targetDepartment.OMSave();
try
{
var result = await MyCall.AssureMedia()
.ContinueWith(_ => MyCall.PlayPrompt(null, [ "ST_OUTOFFICE_SET"], PlayPromptOptions.Blocked), TaskContinuationOptions.OnlyOnRanToCompletion)
.Unwrap();
}
catch
{
//nothing to report. changes are applied
}
return true;
}
catch
{
//just ignore it
return false;
}
}
else
{
MyCall.Warn($"Department '{targetDepartmentNumber}' not found");
return false;
}
}
return false;
}
}
}
Any help would be great
Paulo
Last edited:
