Solved Call Script - single department in Holliday

Status
Not open for further replies.

paulodagraca

3CX MVP
Platinum Partner
Advanced Certified
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??
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 :confused:

Paulo
 
Last edited:
Have you tried the set all departments to holiday mode call script, and then limit to department at the bottom? This may work, i havent tried this myself however.call script.png
 
Hello JoshWS,

Great, never seen the option in this combination.
Tested with Department selection from dropdown list, but it seems that all Department will go into 'Holiday mode' anyway's.
Script should be changed for this to work, i guess.

Paulo
 
Hi @paulodagraca

Replace Lines 22 to 29 with the following, and change XXXXX to the name of the department; note that it is case-sensitive.

{
if (x.Name is "XXXXX")
{
//force office hours until midnight
var groupCurrentTime = x.Now(out var utc, out var timezone, out var groupmode);
x.OverrideExpiresAt = (groupCurrentTime+TimeSpan.FromDays(1)).Date;
x.CurrentGroupHours = GroupHoursMode.ForceHoliday;
MyCall.Info($"{x.Name} set to '{x.CurrentGroupHours}' until {x.OverrideExpiresAt}, timezone={timezone}, groupmode={groupmode}");
}
return x;
 
  • Like
Reactions: KyriacosS_3CX
Status
Not open for further replies.

Forum statistics

Threads
111,973
Messages
590,079
Members
164,899
Latest member
mazet