Skip to Content
Business Trends
Author's profile photo Mahendrakumar Phadtare

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 –

Assigned tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Lothar Hasenkämper
      Lothar Hasenkämper

      Hi Mahendrakumar Phadtare,

      how can I modifiy it to send an alert to more than one recipent?

      regards Lothar