Business Trends
How to use Alerts in SAP Business One – SDK (C#)
#region For Alert Management - Variable Declarations
public static SAPbobsCOM.CompanyService oCmpSrv;
public static MessagesService oMessageService;
public SAPbobsCOM.Message oMessage = null;
public SAPbobsCOM.Messages oMessages = null;
MessageDataColumns pMessageDataColumns = null;
MessageDataColumn pMessageDataColumn = null;
MessageDataLines oLines = null;
MessageDataLine oLine = null;
RecipientCollection oRecipientCollection = null;
#endregion
// Write a Code On Item Event Or any Suitable Trigger
if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK)
{
if (pVal.ItemUID == "16")
{
oCmpSrv = Mahi_Company.GetCompanyService();
oMessageService = (SAPbobsCOM.MessagesService)oCmpSrv.GetBusinessService(ServiceTypes.MessagesService);
oMessage = (SAPbobsCOM.Message)oMessageService.GetDataInterface(MessagesServiceDataInterfaces.msdiMessage);
oMessages = Mahi_Company.GetBusinessObject(BoObjectTypes.oMessages);
string alert = "Select distinct " + '"' + "DocEntry" + '"' + "";
alert += " , " + '"' + "DocNum" + '"' + "";
alert += " , " + '"' + "CardCode" + '"' + "";
alert += " , " + '"' + "CardName" + '"' + "";
alert += " from " + '"' + "ORDR" + '"';
alert += " where " + '"' + "DocEntry" + '"' + " = 4 ";
oRs = (SAPbobsCOM.Recordset)(Main.Mahi_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset));
oRs.DoQuery(alert);
oMessage.User = 1; // Manager - User ID
oMessage.Subject = "Back to BD";
oMessage.Text = System.DateTime.Now.ToString() + " " + "Please Check Sales Orders";
SAPbobsCOM.RecipientCollection RecipientCollection = oMessage.RecipientCollection;
RecipientCollection.Add();
RecipientCollection.Item(0).SendInternal = BoYesNoEnum.tYES;
RecipientCollection.Item(0).SendEmail = BoYesNoEnum.tYES;
RecipientCollection.Item(0).UserCode = "manager";
SAPbobsCOM.MessageDataColumns MessageDataColumns = null;
SAPbobsCOM.MessageDataColumn MessageDataColumn = null;
MessageDataColumns = oMessage.MessageDataColumns;
MessageDataColumn = MessageDataColumns.Add();
MessageDataColumn.ColumnName = "Sales Order";
MessageDataColumn.Link = BoYesNoEnum.tYES;
oLine = MessageDataColumn.MessageDataLines.Add();
oLine.Value = oRs.Fields.Item("DocEntry").Value.ToString();// "DocEntry";
oLine.Object = "17";
oLine.ObjectKey = oRs.Fields.Item("DocEntry").Value.ToString();// "17";
MessageDataColumn = MessageDataColumns.Add();
MessageDataColumn.ColumnName = "BP";// "DocEntry";
MessageDataColumn.Link = BoYesNoEnum.tYES;
oLine = MessageDataColumn.MessageDataLines.Add();
oLine.Value = oRs.Fields.Item("CardCode").Value.ToString(); //"CardCode";
oLine.Object = "2";
oLine.ObjectKey = oRs.Fields.Item("CardCode").Value.ToString(); //"CE00001";
oMessages.Add();
oMessageService.SendMessage(oMessage);
}
}
Alert Message will be like this –
Hi Mahendrakumar Phadtare,
how can I modifiy it to send an alert to more than one recipent?
regards Lothar
Hello Lothar Hasenkämper,
You can add more items in RecipientCollection.
Regards,
Taseeb Saeed
Hi sir, I tried to recreate your idea but the data column for my alert not showing ?
is there setup needed in sld, or there is just an error at my end
Hello Ryan,
Error Message Pls?
Thanks,
Mahendrakumar
Got the same problem. It compiles, it executes without error and the message text is showing, yet the data columns are not showing.
I'm using this in a Dynamic Code Universal function in B1UP, but I don't think that is really the problem.