Skip to Content
Business Trends
Author's profile photo Mahendrakumar D.P.

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

      5 Comments
      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

      Author's profile photo Taseeb Saeed
      Taseeb Saeed

      Hello Lothar Hasenkämper,

      You can add more items in RecipientCollection.

       

      Regards,

      Taseeb Saeed

      Author's profile photo Ryan Lopez
      Ryan Lopez

      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

      Author's profile photo Mahendrakumar D.P.
      Mahendrakumar D.P.
      Blog Post Author

      Hello Ryan,

      Error Message Pls?

       

      Thanks,

      Mahendrakumar

      Author's profile photo Robert Jan Eggens
      Robert Jan Eggens

      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.