No Errors in SAP B1 SDK UI API Code, but Data Not Posting to Database

Despite having no errors in the code for adding a UDO in the SAP B1 SDK UI API, the data is not being posted to the database. How can this issue be resolved?

I have created the form here:

 private void CreateASNForm()
 {
     SAPbouiCOM.FormCreationParams oFormCreationParams = null;
     SAPbouiCOM.Item oItem = null;
     SAPbouiCOM.EditText oEditText = null;
     SAPbouiCOM.Button oButton = null;

     try
     {
         // Check if the form already exists
         SAPbouiCOM.Form oExistingForm = null;
         try
         {
             oExistingForm = SBO_Application.Forms.Item("ASNFrm");
         }
         catch (Exception)
         {
             // Form does not exist
         }

         if (oExistingForm != null)
         {
             // If the form exists but is not visible, close it
             if (!oExistingForm.Visible)
             {
                 oExistingForm.Close();
             }
             else
             {
                 // Form is visible, bring it to the front
                 oExistingForm.Select();
                 SBO_Application.SetStatusBarMessage("Advance Shipping Notification form is already open.", SAPbouiCOM.BoMessageTime.bmt_Short, false);
                 return;
             }
         }

         // Create form with UDO binding
         oFormCreationParams = (SAPbouiCOM.FormCreationParams)SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams);
         oFormCreationParams.UniqueID = "ASNFrm";
         oFormCreationParams.FormType = "ASNFrm";
         oFormCreationParams.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Sizable;
         oFormCreationParams.ObjectType = "WMS_ASN"; // Bind to UDO
         oForm = SBO_Application.Forms.AddEx(oFormCreationParams);
         oForm.Title = "Advance Shipping Notification";

         // Add DataSources
         SAPbouiCOM.DBDataSource oDBDataSourceHeader = oForm.DataSources.DBDataSources.Add("@WMS_ASN");
         SAPbouiCOM.DBDataSource oDBDataSourceLines = oForm.DataSources.DBDataSources.Add("@WMS_ASN_L");

         // Add header fields
         int top = 10;
         int left = 5;
         int width = 150;
         int height = 15;

         #region Header Document
         oItem = oForm.Items.Add("lblDocE", SAPbouiCOM.BoFormItemTypes.it_STATIC);
         oItem.Top = top;
         oItem.Left = left;
         oItem.Width = width;
         oItem.Height = height;
         SAPbouiCOM.StaticText oStaticText = (SAPbouiCOM.StaticText)oItem.Specific;
         oStaticText.Caption = "DocEntry";

         oItem = oForm.Items.Add("txtDocE", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oItem.Top = top;
         oItem.Left = left + width + 5;
         oItem.Width = width;
         oItem.Height = height;
         oEditText = (SAPbouiCOM.EditText)oItem.Specific;
         oEditText.DataBind.SetBound(true, "@WMS_ASN", "DocEntry");
         oEditText.Item.Enabled = false; // Read-only

         top += height + 5;

         oItem = oForm.Items.Add("lblContNr", SAPbouiCOM.BoFormItemTypes.it_STATIC);
         oItem.Top = top;
         oItem.Left = left;
         oItem.Width = width;
         oItem.Height = height;
         oStaticText = (SAPbouiCOM.StaticText)oItem.Specific;
         oStaticText.Caption = "Container Number";

         oItem = oForm.Items.Add("txtContNr", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oItem.Top = top;
         oItem.Left = left + width + 5;
         oItem.Width = width;
         oItem.Height = height;
         oEditText = (SAPbouiCOM.EditText)oItem.Specific;
         oEditText.DataBind.SetBound(true, "@WMS_ASN", "U_ContainerNumber");

         top += height + 5;

         oItem = oForm.Items.Add("lblBLNr", SAPbouiCOM.BoFormItemTypes.it_STATIC);
         oItem.Top = top;
         oItem.Left = left;
         oItem.Width = width;
         oItem.Height = height;
         oStaticText = (SAPbouiCOM.StaticText)oItem.Specific;
         oStaticText.Caption = "Bill of Lading Number";

         oItem = oForm.Items.Add("txtBLNr", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oItem.Top = top;
         oItem.Left = left + width + 5;
         oItem.Width = width;
         oItem.Height = height;
         oEditText = (SAPbouiCOM.EditText)oItem.Specific;
         oEditText.DataBind.SetBound(true, "@WMS_ASN", "U_BLNumber");

         top += height + 5;

         oItem = oForm.Items.Add("lblETA", SAPbouiCOM.BoFormItemTypes.it_STATIC);
         oItem.Top = top;
         oItem.Left = left;
         oItem.Width = width;
         oItem.Height = height;
         oStaticText = (SAPbouiCOM.StaticText)oItem.Specific;
         oStaticText.Caption = "ETA";

         oItem = oForm.Items.Add("txtETA", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oItem.Top = top;
         oItem.Left = left + width + 5;
         oItem.Width = width;
         oItem.Height = height;
         oEditText = (SAPbouiCOM.EditText)oItem.Specific;
         oEditText.DataBind.SetBound(true, "@WMS_ASN", "U_ETA");

         top += height + 5;

         oItem = oForm.Items.Add("lblETD", SAPbouiCOM.BoFormItemTypes.it_STATIC);
         oItem.Top = top;
         oItem.Left = left;
         oItem.Width = width;
         oItem.Height = height;
         oStaticText = (SAPbouiCOM.StaticText)oItem.Specific;
         oStaticText.Caption = "ETD";

         oItem = oForm.Items.Add("txtETD", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oItem.Top = top;
         oItem.Left = left + width + 5;
         oItem.Width = width;
         oItem.Height = height;
         oEditText = (SAPbouiCOM.EditText)oItem.Specific;
         oEditText.DataBind.SetBound(true, "@WMS_ASN", "U_ETD");

         top += height + 5;

         oItem = oForm.Items.Add("lblOrig", SAPbouiCOM.BoFormItemTypes.it_STATIC);
         oItem.Top = top;
         oItem.Left = left;
         oItem.Width = width;
         oItem.Height = height;
         oStaticText = (SAPbouiCOM.StaticText)oItem.Specific;
         oStaticText.Caption = "Origin";

         oItem = oForm.Items.Add("txtOrig", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oItem.Top = top;
         oItem.Left = left + width + 5;
         oItem.Width = width;
         oItem.Height = height;
         oEditText = (SAPbouiCOM.EditText)oItem.Specific;
         oEditText.DataBind.SetBound(true, "@WMS_ASN", "U_Origin");

         top += height + 5;

         oItem = oForm.Items.Add("lblDest", SAPbouiCOM.BoFormItemTypes.it_STATIC);
         oItem.Top = top;
         oItem.Left = left;
         oItem.Width = width;
         oItem.Height = height;
         oStaticText = (SAPbouiCOM.StaticText)oItem.Specific;
         oStaticText.Caption = "Destination";

         oItem = oForm.Items.Add("txtDest", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oItem.Top = top;
         oItem.Left = left + width + 5;
         oItem.Width = width;
         oItem.Height = height;
         oEditText = (SAPbouiCOM.EditText)oItem.Specific;
         oEditText.DataBind.SetBound(true, "@WMS_ASN", "U_Destination");

         top += height + 5;

         oItem = oForm.Items.Add("lblStat", SAPbouiCOM.BoFormItemTypes.it_STATIC);
         oItem.Top = top;
         oItem.Left = left;
         oItem.Width = width;
         oItem.Height = height;
         oStaticText = (SAPbouiCOM.StaticText)oItem.Specific;
         oStaticText.Caption = "Status";

         oItem = oForm.Items.Add("txtStat", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oItem.Top = top;
         oItem.Left = left + width + 5;
         oItem.Width = width;
         oItem.Height = height;
         oEditText = (SAPbouiCOM.EditText)oItem.Specific;
         oEditText.DataBind.SetBound(true, "@WMS_ASN", "U_Status");

         top += height + 15;
         #endregion

         #region Line Items: Grid / Matrix
         // Add a Matrix to the form for displaying line items
         oItem = oForm.Items.Add("matLines", SAPbouiCOM.BoFormItemTypes.it_MATRIX);
         oItem.Top = top;
         oItem.Left = 5;
         oItem.Height = 90;
         oItem.Width = 500;

         SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix)oItem.Specific;
         SAPbouiCOM.Columns oColumns = oMatrix.Columns;

         SAPbouiCOM.Column oColumn = oColumns.Add("colNo", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oColumn.TitleObject.Caption = "#";
         oColumn.Width = 30;
         oColumn.Editable = false; // Prevent focus on # column

         oColumn = oColumns.Add("colPO", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oColumn.TitleObject.Caption = "PO Number";
         oColumn.DataBind.SetBound(true, "@WMS_ASN_L", "U_PONum");
         oColumn.Width = 100;

         // Add ChooseFromList to the PO Number column
         SAPbouiCOM.ChooseFromListCollection oCFLs = oForm.ChooseFromLists;
         SAPbouiCOM.ChooseFromList oCFL;
         SAPbouiCOM.ChooseFromListCreationParams oCFLParams = (SAPbouiCOM.ChooseFromListCreationParams)SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams);
         oCFLParams.MultiSelection = false;
         oCFLParams.ObjectType = "22"; // 22 corresponds to the Purchase Order object type
         oCFLParams.UniqueID = "CFL_PO";
         oCFL = oCFLs.Add(oCFLParams);

         oColumn.ChooseFromListUID = "CFL_PO";
         oColumn.ChooseFromListAlias = "DocNum"; // Use the correct alias for the PO number in the target table

         oColumn = oColumns.Add("colIC", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oColumn.TitleObject.Caption = "Item Code";
         oColumn.DataBind.SetBound(true, "@WMS_ASN_L", "U_ItmCd");
         oColumn.Width = 100;

         // Add ChooseFromList to the form for item codes
         SAPbouiCOM.ChooseFromList oCFLItem;
         SAPbouiCOM.ChooseFromListCreationParams oCFLItemParams = (SAPbouiCOM.ChooseFromListCreationParams)SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams);
         oCFLItemParams.MultiSelection = false;
         oCFLItemParams.ObjectType = "4"; // 4 corresponds to the Item Master Data object type
         oCFLItemParams.UniqueID = "CFL_Item";
         oCFLItem = oForm.ChooseFromLists.Add(oCFLItemParams);

         // Assign the ChooseFromList to the item code column in the matrix
         SAPbouiCOM.Column oItemCodeColumn = oMatrix.Columns.Item("colIC");
         oItemCodeColumn.ChooseFromListUID = "CFL_Item";
         oItemCodeColumn.ChooseFromListAlias = "ItemCode";

         oColumn = oColumns.Add("colDesc", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oColumn.TitleObject.Caption = "Description";
         oColumn.DataBind.SetBound(true, "@WMS_ASN_L", "U_Desc");
         oColumn.Width = 150;

         oColumn = oColumns.Add("colQty", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oColumn.TitleObject.Caption = "Quantity";
         oColumn.DataBind.SetBound(true, "@WMS_ASN_L", "U_Qty");
         oColumn.Width = 80;

         oColumn = oColumns.Add("colUM", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oColumn.TitleObject.Caption = "Unit Measure";
         oColumn.DataBind.SetBound(true, "@WMS_ASN_L", "U_UM");
         oColumn.Width = 80;

         oColumn = oColumns.Add("colBat", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oColumn.TitleObject.Caption = "Batch Number";
         oColumn.DataBind.SetBound(true, "@WMS_ASN_L", "U_Batch");
         oColumn.Width = 100;

         oColumn = oColumns.Add("colMfg", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oColumn.TitleObject.Caption = "Manufacturing Date";
         oColumn.DataBind.SetBound(true, "@WMS_ASN_L", "U_MfgDt");
         oColumn.Width = 100;

         oColumn = oColumns.Add("colExp", SAPbouiCOM.BoFormItemTypes.it_EDIT);
         oColumn.TitleObject.Caption = "Expiration Date";
         oColumn.DataBind.SetBound(true, "@WMS_ASN_L", "U_ExpDt");
         oColumn.Width = 100;
         #endregion

         // Adjust the top position to add buttons below the matrix
         top = 280;

         // Add buttons for actions
         oItem = oForm.Items.Add("btnAdd", SAPbouiCOM.BoFormItemTypes.it_BUTTON);
         oItem.Visible = true;
         oItem.Top = top;
         oItem.Left = 5;
         oButton = (SAPbouiCOM.Button)oItem.Specific;
         oButton.Caption = "Add";

         oItem = oForm.Items.Add("btnCanc", SAPbouiCOM.BoFormItemTypes.it_BUTTON);
         oItem.Top = top;
         oItem.Left = 75;
         oButton = (SAPbouiCOM.Button)oItem.Specific;
         oButton.Caption = "Cancel";

         // Initialize matrix with one row
         AddRowToMatrix("ASNFrm");

         oForm.Visible = true;
     }
     catch (Exception ex)
     {
         SBO_Application.SetStatusBarMessage("Error creating ASN form: " + ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, true);
     }
 }

We call it on the SBO_Application_ItemEvent(string FormUID, ref ItemEvent pVal, out bool BubbleEvent);

private void SBO_Application_ItemEvent(string FormUID, ref ItemEvent pVal, out bool BubbleEvent)
{
  if (pVal.EventType == BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "btnAdd" && !pVal.BeforeAction)
  {
    HandleAddOrUpdate(pVal.FormUID);
  }
}

Code for Handling the Add or Update

 private void HandleAddOrUpdate(string FormUID)
 {
     try
     {
         oForm = SBO_Application.Forms.Item(FormUID);
         MessageBox.Show(FormUID);
         if (oForm.Mode != BoFormMode.fm_ADD_MODE && oForm.Mode != BoFormMode.fm_UPDATE_MODE)
         {
             SBO_Application.SetStatusBarMessage("Form is not in add or update mode.", BoMessageTime.bmt_Short, true);
             return;
         }

         // Start transaction
         oCompany.StartTransaction();

         // Ensure you have all data sources bound correctly
         SAPbouiCOM.DBDataSource oDBDataSourceHeader = oForm.DataSources.DBDataSources.Item("@WMS_ASN");
         SAPbouiCOM.DBDataSource oDBDataSourceLines = oForm.DataSources.DBDataSources.Item("@WMS_ASN_L");

         // Save header fields with error handling
         try
         {
             oDBDataSourceHeader.SetValue("U_ContainerNumber", 0, ((SAPbouiCOM.EditText)oForm.Items.Item("txtContNr").Specific).Value);
             oDBDataSourceHeader.SetValue("U_BLNumber", 0, ((SAPbouiCOM.EditText)oForm.Items.Item("txtBLNr").Specific).Value);
             oDBDataSourceHeader.SetValue("U_ETA", 0, ((SAPbouiCOM.EditText)oForm.Items.Item("txtETA").Specific).Value);
             oDBDataSourceHeader.SetValue("U_ETD", 0, ((SAPbouiCOM.EditText)oForm.Items.Item("txtETD").Specific).Value);
             oDBDataSourceHeader.SetValue("U_Origin", 0, ((SAPbouiCOM.EditText)oForm.Items.Item("txtOrig").Specific).Value);
             oDBDataSourceHeader.SetValue("U_Destination", 0, ((SAPbouiCOM.EditText)oForm.Items.Item("txtDest").Specific).Value);
             oDBDataSourceHeader.SetValue("U_Status", 0, ((SAPbouiCOM.EditText)oForm.Items.Item("txtStat").Specific).Value);
         }
         catch (Exception ex)
         {
             SBO_Application.SetStatusBarMessage("Error setting header field values: " + ex.Message, BoMessageTime.bmt_Short, true);
             if (oCompany.InTransaction)
                 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
             return;
         }

         // Save line items with error handling
         SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix)oForm.Items.Item("matLines").Specific;
         for (int i = 1; i <= oMatrix.RowCount; i++)
         {
             try
             {
                 oDBDataSourceLines.SetValue("U_PONum", i - 1, ((SAPbouiCOM.EditText)oMatrix.Columns.Item("colPO").Cells.Item(i).Specific).Value);
                 oDBDataSourceLines.SetValue("U_ItmCd", i - 1, ((SAPbouiCOM.EditText)oMatrix.Columns.Item("colIC").Cells.Item(i).Specific).Value);
                 oDBDataSourceLines.SetValue("U_Desc", i - 1, ((SAPbouiCOM.EditText)oMatrix.Columns.Item("colDesc").Cells.Item(i).Specific).Value);
                 oDBDataSourceLines.SetValue("U_Qty", i - 1, ((SAPbouiCOM.EditText)oMatrix.Columns.Item("colQty").Cells.Item(i).Specific).Value);
                 oDBDataSourceLines.SetValue("U_UM", i - 1, ((SAPbouiCOM.EditText)oMatrix.Columns.Item("colUM").Cells.Item(i).Specific).Value);
                 oDBDataSourceLines.SetValue("U_Batch", i - 1, ((SAPbouiCOM.EditText)oMatrix.Columns.Item("colBat").Cells.Item(i).Specific).Value);
                 oDBDataSourceLines.SetValue("U_MfgDt", i - 1, ((SAPbouiCOM.EditText)oMatrix.Columns.Item("colMfg").Cells.Item(i).Specific).Value);
                 oDBDataSourceLines.SetValue("U_ExpDt", i - 1, ((SAPbouiCOM.EditText)oMatrix.Columns.Item("colExp").Cells.Item(i).Specific).Value);
             }
             catch (Exception ex)
             {
                 SBO_Application.SetStatusBarMessage("Error setting line field values at row " + i + ": " + ex.Message, BoMessageTime.bmt_Short, true);
                 if (oCompany.InTransaction)
                     oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                 return;
             }
         }

         // Update the form
         try
         {
             oForm.Update();
             if (oCompany.InTransaction)
                 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
             SBO_Application.SetStatusBarMessage("Record added/updated successfully.", BoMessageTime.bmt_Short, false);
         }
         catch (Exception ex)
         {
             SBO_Application.SetStatusBarMessage("Error updating the record: " + ex.Message, BoMessageTime.bmt_Short, true);
             if (oCompany.InTransaction)
                 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
         }
     }
     catch (Exception ex)
     {
         SBO_Application.SetStatusBarMessage("Error handling add/update: " + ex.Message, BoMessageTime.bmt_Short, true);
         if (oCompany.InTransaction)
             oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
     }
 }

Need Guidance: Creating Advanced Shipping Notification Form with UDO Tables in SAP B1 SDK Using C#.NET – Source Code Not Working, Expecting Assistance to Identify Mistakes

New contributor

Ben Penafiel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật