Hello!
I've made an automation script that is triggered by a booking event to alert about an upcoming booking. But, can I display a pop-up message to specific users or user groups to alert them? The only way I've found to do this is using the FindInteractiveClient method, but it only allows me to display a simple message.
Thanks in advance
Hi, you can do so by letting the script send a 'BroadCastPopupRequestMessage', in which you can specify the users and/or user groups that need to be notified.
Code example below, including a countdown timer.
Note that in this script, the users/user groups are passed via input parameters. Of course you could also hard-code those.
For domain users the username should be in the format "domain\user name", for local users the names should be in the format "user name".
using Skyline.DataMiner.Automation;
using Skyline.DataMiner.Net;
using Skyline.DataMiner.Net.Broadcast;
using Skyline.DataMiner.Net.Messages;
using Skyline.DataMiner.Net.ResourceManager.Objects;
using Skyline.DataMiner.Library.Solutions.SRM;
using System;
using System.Collections.Generic;
using System.Linq;public class Script
{
public Engine engine;public ResourceManagerHelper resourceHelper;
public BroadcastPopupRequestMessage popup;
public void Run(Engine engine)
{
this.engine = engine;
popup = new BroadcastPopupRequestMessage();
resourceHelper = new ResourceManagerHelper();
resourceHelper.RequestResponseEvent += (sender, e) => e.responseMessage = engine.SendSLNetSingleResponseMessage(e.requestMessage);string reservationGuid = engine.GetScriptParam("ReservationGuid").Value;
string userNames = engine.GetScriptParam("UserNames").Value;
string groupNames = engine.GetScriptParam("GroupNames").Value;ReservationInstance reservationInstance = GetReservationInstanceFromGuid(reservationGuid);
List<string> usersToNotify = userNames.ToLower() == "all" ? null : userNames.Split(',').ToList();
List<string> groupsToNotify = groupNames.ToLower() == "all" ? null : groupNames.Split(',').ToList();
InitPopup(reservationInstance, usersToNotify, groupsToNotify);LaunchPopup();
}public ReservationInstance GetReservationInstanceFromGuid(string guidString)
{
Guid reservationGuid;
if (String.IsNullOrEmpty(guidString) || !Guid.TryParse(guidString, out reservationGuid))
{
return null;
}return resourceHelper.GetReservationInstance(reservationGuid);
}public void InitPopup(ReservationInstance reservationInstance, List<string> userNames, List<string> groupNames)
{
string format = "u";popup.PopupInfo = new PopupInfo
{
Expiration = reservationInstance.Start.ToLocalTime() + reservationInstance.GetPreRoll(),
Message = String.Format("Booking '" + reservationInstance.Name + "' will start in [Subtract:{0},[DataMinerTime:Format={1}]]", (reservationInstance.Start.ToLocalTime() + reservationInstance.GetPreRoll()).ToString(format), format),
Source = reservationInstance.ID,
Title = reservationInstance.Name + " about to start"
};if (userNames != null || !userNames.Equals("none")) popup.PopupInfo.UserNames = userNames;
if (groupNames != null || !groupNames.Equals("none")) popup.PopupInfo.GroupNames = groupNames;engine.GenerateInformation("Users=" + userNames[0]);
engine.GenerateInformation("Groups=" + groupNames[0]);
}public void LaunchPopup()
{
engine.GenerateInformation("Generating Popup");
engine.SendSLNetMessage(popup);
}
}
Hello Ruben,
Thank you so much!
Best Regards