Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
mk1909_sap
Active Participant
17,025

Hello All,

Greetings !!!

I have Created One Simple Form For SAP Business One SDK Freshers. Kindly Find the attached Screens Also For Your Reference. All SAP Business One Standard Functionalities are covered in this Simple Form Application.

1.UI/DI Connection i.e Single sign in SAP Business One
2.Created of Used Defined Table as Table Name = "GOD_ODIN" and Table Description = "GOD Simple Form" of Document Type
3.Created Fields in "GOD_ODIN" as Cardcode,CardName,VenCode,VenName and DocDate
3.Registered "GOD_ODIN" in SAP Business One with UDO Code as "GOD_ODIN" and Changed User Defined Form "Object Type" Property to "GOD_ODIN".
4.Added User Defined Menus Using XML Operations in Modules Menu at 13th Position
5.Attched Simple Form To User Defined Menu Simple Form
6.User Defined ChooseFromLists are attached to Customer and Vendor
7.Default Document Date will be Todays Date
8.Add/Update/Find and Navigation Functionalities on User Defined Screen.
9.User Defined Choosefrom lists are added on Customer and Vendor Fields.

This Application is Developed in SAP Business One 9.2 PL8.

How To Use This Code ?
1. Creat New Visual Studio Project
2. Add One Module For Startup
3. Add 3 Classes For 1.1) Simple Form 1.2) Main Class 1.3) Utilities Class.
4. Utilities Class - All Common Functions are Defined in Utilities class
4. Add SAPBobosCOM and SAPBouiCOM references in Project
5. Copy and Paste the attached Codes in Corresponding Classes

 

Project Code will be as Follows - For Simple Form Class

Imports System.Threading

Imports System.IO

Imports System

Public Class clsSimpleForm



#Region "Declaration"

    'For UI

    Dim GOD_Form As SAPbouiCOM.Form

#End Region



#Region "Item Event"

    Public Sub ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean)

        If pVal.BeforeAction Then

        Else

            Select Case pVal.EventType

                Case SAPbouiCOM.BoEventTypes.et_FORM_LOAD

                    GOD_Form = GOD_Main.GOD_Application.Forms.GetForm("frmSimpleForm", pVal.FormTypeCount)

                    'To Enable Navigation Menus - MoveFirst/MoveNext/MovePreviouse and MoveLast

                    GOD_Form.EnableMenu("1288", True)

                    GOD_Form.EnableMenu("1289", True)

                    GOD_Form.EnableMenu("1290", True)

                    GOD_Form.EnableMenu("1291", True)

                    GOD_Form.Mode = SAPbouiCOM.BoFormMode.fm_ADD_MODE

                Case SAPbouiCOM.BoEventTypes.et_KEY_DOWN

                    If pVal.CharPressed = "9" Then

                        GOD_Form = GOD_Main.GOD_Application.Forms.GetForm("frmSimpleForm", pVal.FormTypeCount)

                        If pVal.ItemUID = "edVendorNm" Then '

                            If GOD_Form.Items.Item("edVendorNm").Specific.value = "" Then

                                GOD_Main.GOD_SourceForm = GOD_Main.GOD_Application.Forms.GetForm("frmSimpleForm", pVal.FormTypeCount)

                                GOD_Main.strColSelectedinCFL = "Vendor Name"

                                GOD_Main.CLFHeader("edVendorNm", FormUID, "CFL_Vendor_SimpleForm", "CFLHeader")

                                'By Default Current Date Displayed on Document Date

                                GOD_Form.Items.Item("edDocDate").Specific.value = DateTime.Now.ToString("yyyyMMdd")

                            End If

                        ElseIf pVal.ItemUID = "edCustName" Then

                            If GOD_Form.Items.Item("edCustName").Specific.value = "" Then

                                GOD_Main.GOD_SourceForm = GOD_Main.GOD_Application.Forms.GetForm("frmSimpleForm", pVal.FormTypeCount)

                                GOD_Main.strColSelectedinCFL = "Vendor Name"

                                GOD_Main.CLFHeader("edCustName", FormUID, "CFL_Customer_SimpleForm", "CFLHeader")

                            End If

                        End If

                    End If

            End Select

        End If

    End Sub

#End Region



#Region "Menu Events"

    Public Sub MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean)

        Try

            If pVal.BeforeAction Then

            Else

                If (pVal.MenuUID = "1281" Or pVal.MenuUID = "1282" Or pVal.MenuUID = "1289" Or pVal.MenuUID = "1290" Or pVal.MenuUID = "1291" Or pVal.MenuUID = "1288") Then

                    If GOD_Main.GOD_Application.Forms.ActiveForm.TypeEx = "frmSimpleForm" Then

                        GOD_Form = GOD_Main.GOD_Application.Forms.GetForm("frmSimpleForm", 1)

                        GOD_Form.EnableMenu("5890", True)

                        GOD_Form.DataBrowser.BrowseBy = "12"

                    End If

                End If

                If pVal.MenuUID = "mnuSimple" Then

                    GOD_Main.objUtilities.LoadForm("Simple Form.xml", "frmSimpleForm", "frmSimpleForm", ResourceType.Embeded)

                End If

            End If

        Catch ex As Exception

            GOD_Main.GOD_Application.MessageBox(ex.Message)

        End Try

    End Sub

#End Region



End Class


 

2. Main Class Code

 

Imports System.Reflection

Imports System.Diagnostics

Imports System.Net.Mail

Imports System.Net

Imports System.Text

Imports SAPbobsCOM

Public Class clsMain



#Region "Declaration"

    Public WithEvents GOD_Application As SAPbouiCOM.Application

    Public GOD_Company As SAPbobsCOM.Company



    'Creating Instances For Each Class

    Public objUtilities As clsUtilities

    Public objSimpleForm As clsSimpleForm

    Public objChooseFromList As clsChooseFromList

    Public objChoose As clsChooseFromList



    'For UI

    Public GOD_SourceForm As SAPbouiCOM.Form

    Public strColSelectedinCFL As String

    Public SourceRowNo1 As Integer

    'For DI

    Public oDBs_Head As SAPbouiCOM.DBDataSource

    Public oDBs_Detail As SAPbouiCOM.DBDataSource

    Public GOD_Rec As SAPbobsCOM.Recordset

#End Region



#Region "New"

    Public Sub New()

        objUtilities = New clsUtilities

        objSimpleForm = New clsSimpleForm

        objChooseFromList = New clsChooseFromList

        objChoose = New clsChooseFromList

    End Sub

#End Region



#Region "Initialise"

    Public Function Initialise() As Boolean

        GOD_Application = objUtilities.GetApplication()

        objUtilities.ShowSuccessMessage("Please wait for the Simple Form Add-on Icon to appear in menu. It may take few minutes based on Server and Network speed.")

        GOD_Company = objUtilities.GetCompany(GOD_Application)

        Call CreateTables()

        objUtilities.LoadFromXML("Menus.xml", ResourceType.Embeded)

        Call RegisterUDO()

        Call CreateObjects()

        objUtilities.ShowSuccessMessage("Simple Form Add-on Connected. You may now proceed to use add-on.")

        Return True

    End Function

#End Region



#Region "Create Objects"

    Private Sub CreateObjects()

        objChooseFromList = New clsChooseFromList

    End Sub

#End Region



#Region "Load Choosefrom List"

    Public Sub CLFHeader(ByVal ItemUID As String, ByVal FormUID As String, ByVal CFLName As String, ByVal FormTypeEx As String)

        Dim objChooseForm As SAPbouiCOM.Form

        clsChooseFromList.ItemUID = ItemUID

        clsChooseFromList.SourceFormUID = FormUID

        clsChooseFromList.CFLChoice = CFLName

        If objUtilities.FormExist(FormTypeEx) = False Then

            GOD_Main.objUtilities.LoadForm("CFLHeader.xml", "CFLHeader", "CFLHeader", ResourceType.Embeded)

            objChooseForm = GOD_Main.GOD_Application.Forms.ActiveForm

            objChoose.databound(objChooseForm, GOD_SourceForm, oDBs_Detail, oDBs_Detail, "", SourceRowNo1)

        End If

    End Sub



    Public Sub CFLDetail(ByVal ItemUID As String, ByVal colUID As String, ByVal FormUID As String, ByVal CFLName As String, SourceRow1 As Integer, ByVal FormTypeEx As String)

        Dim objChooseForm As SAPbouiCOM.Form

        SourceRowNo1 = SourceRow1

        clsChooseFromList.ItemUID = ItemUID

        clsChooseFromList.SourceFormUID = FormUID

        clsChooseFromList.CFLChoice = CFLName

        If objUtilities.FormExist(FormTypeEx) = False Then

            GOD_Main.objUtilities.LoadForm("CFLDetail.xml", "CFLDetail", "CFLDetail", ResourceType.Embeded)

            objChooseForm = GOD_Main.GOD_Application.Forms.ActiveForm

            objChoose.databound(objChooseForm, GOD_SourceForm, oDBs_Detail, oDBs_Detail, "", SourceRowNo1)

        End If

    End Sub

#End Region



#Region "Register UDO"

    Private Sub RegisterUDO()

        Dim findAliasNDescription = New String(,) {{"DocEntry", "DocEntry"}} 'For Find in Default Form - DocEntry Column

        If Not objUtilities.UDOExists("GOD_ODIN") = True Then

            objUtilities.registerUDO("GOD_ODIN", "GOD Simple Form", SAPbobsCOM.BoUDOObjType.boud_Document, findAliasNDescription, "GOD_ODIN", "", "", "", "", "", "", "", "", SAPbobsCOM.BoYesNoEnum.tNO)

        End If

    End Sub

#End Region



#Region "Create Table"

    Public Sub CreateTables()

        Try

            'Daily Inward Screen GOD_ODIN

            objUtilities.CreateTable("GOD_ODIN", "GOD Simple Form", SAPbobsCOM.BoUTBTableType.bott_Document)

            objUtilities.AddAlphaField("@GOD_ODIN", "CardCode", "Customer Code", 120)

            objUtilities.AddAlphaField("@GOD_ODIN", "CardName", "Client Name", 150)

            objUtilities.AddAlphaField("@GOD_ODIN", "VenCode", "Vendor Code", 120)

            objUtilities.AddAlphaField("@GOD_ODIN", "VenName", "Vendor Name", 150)

            objUtilities.AddDateField("@GOD_ODIN", "DocDate", "Document Date", BoFldSubTypes.st_None)

        Catch ex As Exception

            GOD_Main.GOD_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)

        Finally

        End Try

    End Sub

#End Region



#Region "Item Event"

    Public Sub ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles GOD_Application.ItemEvent

        Try

            Select Case pVal.FormTypeEx

                Case "frmSimpleForm"

                    objSimpleForm.ItemEvent(FormUID, pVal, BubbleEvent)

                Case "CFLHeader"

                    objChooseFromList.ItemEvent(FormUID, pVal, BubbleEvent)

                Case "CFLDetail"

                    objChooseFromList.ItemEvent(FormUID, pVal, BubbleEvent)

            End Select

        Catch ex As Exception

            GOD_Application.MessageBox(ex.Message)

        End Try

    End Sub

#End Region



#Region "Menu Events"

    Public Sub MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles GOD_Application.MenuEvent

        If pVal.BeforeAction = False Then

            If (pVal.MenuUID = "1293" Or pVal.MenuUID = "1292" Or pVal.MenuUID = "1281" Or pVal.MenuUID = "1282" Or pVal.MenuUID = "1289" Or pVal.MenuUID = "1290" Or pVal.MenuUID = "1291" Or pVal.MenuUID = "1288" Or pVal.MenuUID = "1292") Then

                If GOD_Application.Forms.ActiveForm.TypeEx = "frmSimpleForm" Then

                    objSimpleForm.MenuEvent(pVal, BubbleEvent)

                End If

            ElseIf pVal.MenuUID = "mnuSimple" Then

                objSimpleForm.MenuEvent(pVal, BubbleEvent)

            End If

        End If

    End Sub

#End Region



#Region "Application Event"

    Private Sub ApplicationEvent(ByVal EventType As SAPbouiCOM.BoAppEventTypes) Handles GOD_Application.AppEvent

        If (EventType = SAPbouiCOM.BoAppEventTypes.aet_CompanyChanged Or EventType = SAPbouiCOM.BoAppEventTypes.aet_ServerTerminition Or EventType = SAPbouiCOM.BoAppEventTypes.aet_ShutDown Or EventType = SAPbouiCOM.BoAppEventTypes.aet_FontChanged Or EventType = SAPbouiCOM.BoAppEventTypes.aet_LanguageChanged) Then

            CloseApp()

        End If

    End Sub

#End Region



End Class








 

3. Startup Class Code

 

Module modStartUp



#Region "Declaration"

    Public GOD_Main As clsMain

#End Region



#Region "Main"

    Public Sub Main()

        GOD_Main = New clsMain

        If (GOD_Main.Initialise()) Then

            System.Windows.Forms.Application.Run()

        Else

            GOD_Main.GOD_Application.StatusBar.SetText("Error in Connection", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

        End If

    End Sub

#End Region



#Region "Close Application"

    '*****************************************************************

    'Type               : CloseAPP

    'Parameter          : 

    'Return Value       : 

    'Author             : Mahendrakumar Phadtare

    'Created Date       : 

    'Purpose            : To Stop Addon exe and Close All Open SAP Screens on Addon Addon Disconnection

    'Addon              : GOD Close Application

    '*****************************************************************

    Public Sub CloseApp()

        GOD_Main.GOD_Application.StatusBar.SetText("Simple Application Add-on Being Disconnected [message 10000-03].", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

        GOD_Main.objUtilities.LoadFromXML("RemoveMenus.xml", ResourceType.Embeded)

        System.Windows.Forms.Application.Exit()

    End Sub

#End Region



End Module


 

4. Utilities Class code

 

Imports System.Reflection

Public Class clsUtilities

    Public strLastErrorCode As String

    Public strLastError As String



#Region "Field Creations"

    'To Add Alphnumeric Field in Table

    Public Sub AddAlphaField(ByVal TableName As String, ByVal ColumnName As String, ByVal ColDescription As String, ByVal Size As Integer, Optional ByVal DefaultValue As String = "")

        Try

            addField(TableName, ColumnName, ColDescription, SAPbobsCOM.BoFieldTypes.db_Alpha, Size, SAPbobsCOM.BoFldSubTypes.st_None, "", "", DefaultValue)

        Catch ex As Exception

            GOD_Main.GOD_Application.StatusBar.SetText(ex.Message & " Field Name is " & ColDescription, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)

        End Try

    End Sub

#End Region



#Region "Add UDO in SAP Business One Application "

    Private Sub AddUDO(ByVal strUDO As String, ByVal strDesc As String, ByVal strTable As String, _

                                Optional ByVal sFinCHRG As String = "", Optional ByVal sFind2 As String = "", _

                                Optional ByVal strChildTbl As String = "", Optional ByVal nObjectType As SAPbobsCOM.BoUDOObjType = SAPbobsCOM.BoUDOObjType.boud_Document)

        Dim oUserObjectMD As SAPbobsCOM.UserObjectsMD = Nothing

        Try

            oUserObjectMD = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD)

            If oUserObjectMD.GetByKey(strUDO) = 0 Then

                oUserObjectMD.CanCancel = SAPbobsCOM.BoYesNoEnum.tYES

                oUserObjectMD.CanClose = SAPbobsCOM.BoYesNoEnum.tYES

                oUserObjectMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tNO

                oUserObjectMD.CanDelete = SAPbobsCOM.BoYesNoEnum.tNO

                oUserObjectMD.CanFind = SAPbobsCOM.BoYesNoEnum.tYES

                If sFinCHRG <> "" And sFind2 <> "" Then

                    oUserObjectMD.FindColumns.ColumnAlias = sFinCHRG

                    oUserObjectMD.FindColumns.Add()

                    oUserObjectMD.FindColumns.SetCurrentLine(1)

                    oUserObjectMD.FindColumns.ColumnAlias = sFind2

                    oUserObjectMD.FindColumns.Add()

                End If

                oUserObjectMD.CanLog = SAPbobsCOM.BoYesNoEnum.tNO

                oUserObjectMD.LogTableName = ""

                oUserObjectMD.CanYearTransfer = SAPbobsCOM.BoYesNoEnum.tNO

                oUserObjectMD.ExtensionName = ""

                If strChildTbl <> "" Then

                    oUserObjectMD.ChildTables.TableName = strChildTbl

                End If

                oUserObjectMD.ManageSeries = SAPbobsCOM.BoYesNoEnum.tNO

                oUserObjectMD.Code = strUDO

                oUserObjectMD.Name = strDesc

                oUserObjectMD.ObjectType = SAPbobsCOM.BoUDOObjType.boud_Document

                oUserObjectMD.TableName = strTable

                If oUserObjectMD.Add() <> 0 Then

                    Throw New Exception(GOD_Main.GOD_Company.GetLastErrorDescription)

                End If

            End If

        Catch ex As Exception

            Throw ex

        Finally

            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserObjectMD)

            oUserObjectMD = Nothing

            GC.WaitForPendingFinalizers()

            GC.Collect()

        End Try

    End Sub

#End Region



#Region "GetApplication"

    Public Function GetApplication() As SAPbouiCOM.Application

        Dim objApp As SAPbouiCOM.Application

        Dim objSboGuiApi As New SAPbouiCOM.SboGuiApi

        Dim strConnectionString As String = Environment.GetCommandLineArgs.GetValue(1)

        objSboGuiApi = New SAPbouiCOM.SboGuiApi

        objSboGuiApi.Connect(strConnectionString)

        objApp = objSboGuiApi.GetApplication()

        Return objApp

    End Function

#End Region



    Public Function ShowSuccessMessage(ByVal Message As String)

        GOD_Main.GOD_Application.StatusBar.SetText(Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)

        Return Nothing

    End Function



#Region "GET COMPANY"

    Public Function GetCompany(ByVal SBOApplication As SAPbouiCOM.Application) As SAPbobsCOM.Company

        Dim GOD_Company As SAPbobsCOM.Company

        Dim strCookie As String

        Dim strCookieContext As String

        Try

            GOD_Company = New SAPbobsCOM.Company

            strCookie = GOD_Company.GetContextCookie

            strCookieContext = SBOApplication.Company.GetConnectionContext(strCookie)

            GOD_Company.SetSboLoginContext(strCookieContext)

            If GOD_Company.Connect <> 0 Then

                strLastError = "Connection Error"

                SBOApplication.StatusBar.SetText("GOD Simple Form Addon Connection Error. Error is " & GOD_Main.GOD_Company.GetLastErrorDescription, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

                Return Nothing

            End If

            Return GOD_Company

        Catch ex As Exception

            SBOApplication.MessageBox(ex.Message)

            Return Nothing

        End Try

    End Function

#End Region



#Region "Register UDO In SAP Business One "

    'To Register Use Defined Object in SAP Business One

    Function registerUDO(ByVal UDOCode As String, ByVal UDOName As String, ByVal UDOType As SAPbobsCOM.BoUDOObjType, ByVal findAliasNDescription As String(,), ByVal parentTableName As String, Optional ByVal childTable1 As String = "", Optional ByVal childTable2 As String = "", Optional ByVal childTable3 As String = "", Optional ByVal childTable4 As String = "", Optional ByVal childTable5 As String = "", Optional ByVal childTable6 As String = "", Optional ByVal childTable7 As String = "", Optional ByVal childTable8 As String = "", Optional ByVal LogOption As SAPbobsCOM.BoYesNoEnum = SAPbobsCOM.BoYesNoEnum.tNO, Optional ByVal DefFormOption As SAPbobsCOM.BoYesNoEnum = SAPbobsCOM.BoYesNoEnum.tNO, Optional ByVal MenuItem As SAPbobsCOM.BoYesNoEnum = SAPbobsCOM.BoYesNoEnum.tNO, Optional ByVal MenuCaption As String = "", Optional ByVal FatherMenuId As String = "", Optional ByVal Position As Integer = 0) As Boolean

        Dim actionSuccess As Boolean = False

        Try

            registerUDO = False

            Dim v_udoMD As SAPbobsCOM.UserObjectsMD

            v_udoMD = GOD_Main.objUtilities.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD)

            v_udoMD.CanCancel = SAPbobsCOM.BoYesNoEnum.tNO

            v_udoMD.CanClose = SAPbobsCOM.BoYesNoEnum.tNO

            v_udoMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tNO

            v_udoMD.CanDelete = SAPbobsCOM.BoYesNoEnum.tYES

            v_udoMD.CanFind = SAPbobsCOM.BoYesNoEnum.tYES

            v_udoMD.CanLog = LogOption

            v_udoMD.CanYearTransfer = SAPbobsCOM.BoYesNoEnum.tYES

            v_udoMD.ManageSeries = SAPbobsCOM.BoYesNoEnum.tYES

            v_udoMD.Code = UDOCode

            v_udoMD.Name = UDOName

            v_udoMD.TableName = parentTableName

            If LogOption = SAPbobsCOM.BoYesNoEnum.tYES Then

                v_udoMD.LogTableName = "A" & parentTableName

            End If

            If DefFormOption = SAPbobsCOM.BoYesNoEnum.tYES Then

                v_udoMD.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tYES

                v_udoMD.MenuItem = SAPbobsCOM.BoYesNoEnum.tYES

                v_udoMD.MenuCaption = MenuCaption

                v_udoMD.FatherMenuID = FatherMenuId

                v_udoMD.Position = Position

            End If

            v_udoMD.ObjectType = UDOType

            For i As Int16 = 0 To findAliasNDescription.GetLength(0) - 1

                If i > 0 Then v_udoMD.FindColumns.Add()

                v_udoMD.FindColumns.ColumnAlias = findAliasNDescription(i, 0)

                v_udoMD.FindColumns.ColumnDescription = findAliasNDescription(i, 1)

            Next

            If childTable1 <> "" Then

                v_udoMD.ChildTables.TableName = childTable1

                v_udoMD.ChildTables.Add()

            End If

            If childTable2 <> "" Then

                v_udoMD.ChildTables.TableName = childTable2

                v_udoMD.ChildTables.Add()

            End If

            If childTable3 <> "" Then

                v_udoMD.ChildTables.TableName = childTable3

                v_udoMD.ChildTables.Add()

            End If

            If childTable4 <> "" Then

                v_udoMD.ChildTables.TableName = childTable4

                v_udoMD.ChildTables.Add()

            End If

            If v_udoMD.Add() = 0 Then

                registerUDO = True

                GOD_Main.GOD_Application.StatusBar.SetText("Successfully Registered UDO >" & UDOCode & ">" & UDOName & ".", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)

            Else

                GOD_Main.GOD_Application.StatusBar.SetText("Failed to Register UDO >" & UDOCode & ">" & UDOName & " >" & GOD_Main.GOD_Company.GetLastErrorDescription, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

                registerUDO = False

            End If

            System.Runtime.InteropServices.Marshal.ReleaseComObject(v_udoMD)

            v_udoMD = Nothing

            GC.Collect()

        Catch ex As Exception

            GOD_Main.GOD_Application.MessageBox(ex.Message)

        End Try

    End Function

#End Region



#Region "Check for UDO Exists"

    'To Check If User Defined Object already exists or not

    Public Function UDOExists(ByVal code As String) As Boolean

        GC.Collect()

        Dim v_UDOMD As SAPbobsCOM.UserObjectsMD

        Dim v_ReturnCode As Boolean

        v_UDOMD = GOD_Main.objUtilities.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD)

        v_ReturnCode = v_UDOMD.GetByKey(code)

        System.Runtime.InteropServices.Marshal.ReleaseComObject(v_UDOMD)

        v_UDOMD = Nothing

        Return v_ReturnCode

    End Function

#End Region



    Public Function GetBusinessObject(ByVal ObjectType As SAPbobsCOM.BoObjectTypes) As Object

        Return GOD_Main.GOD_Company.GetBusinessObject(ObjectType)

    End Function



#Region "Load Form"

    'To Load Form in SAP Business One

    Sub LoadForm(ByVal XMLFile As String, ByVal FormType As String, ByVal FormUID As String, Optional ByVal FileType As ResourceType = ResourceType.Content)

        Try

            Dim xmldoc As New Xml.XmlDocument

            Dim Streaming As System.IO.Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Simple_Form." + XMLFile)

            Dim StreamRead As New System.IO.StreamReader(Streaming, True)

            xmldoc.LoadXml(StreamRead.ReadToEnd)

            StreamRead.Close()

            Dim r As New Random

            r.Next(1000)

            If Not xmldoc.SelectSingleNode("//form") Is Nothing Then

                xmldoc.SelectSingleNode("//form").Attributes.GetNamedItem("uid").Value = xmldoc.SelectSingleNode("//form").Attributes.GetNamedItem("uid").Value & "_" & r.Next

                GOD_Main.GOD_Application.LoadBatchActions(xmldoc.InnerXml)

            End If

        Catch ex As Exception

            GOD_Main.GOD_Application.MessageBox(ex.Message)

        End Try

    End Sub

#End Region



#Region "LOAD FROM XML"

    'To Load Sap Bbusiness One Form in SAP Business One Using XML Operations

    Public Sub LoadFromXML(ByVal FileName As String, Optional ByVal FileType As ResourceType = ResourceType.Content)

        Dim oXmlDoc As Xml.XmlDocument

        Dim oXmlStream As System.IO.Stream

        oXmlDoc = New Xml.XmlDocument

        Try

            If FileType = ResourceType.Content Then

                oXmlDoc.Load(FileName)

            Else

                oXmlStream = System.Reflection.Assembly.LoadFrom(System.Windows.Forms.Application.ExecutablePath).GetManifestResourceStream(GetType(modStartUp).Namespace & "." & FileName)

                oXmlDoc.Load(oXmlStream)

            End If

            GOD_Main.GOD_Application.LoadBatchActions(oXmlDoc.InnerXml)

        Catch ex As Exception

            GOD_Main.GOD_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)

        End Try

    End Sub

#End Region



    Public Function FormExist(ByVal FormTypeEx As String) As Boolean

        Dim intLoop As Integer

        For intLoop = GOD_Main.GOD_Application.Forms.Count - 1 To 0 Step -1

            If Trim(FormTypeEx) = Trim(GOD_Main.GOD_Application.Forms.Item(intLoop).TypeEx) Then

                GOD_Main.GOD_Application.Forms.Item(intLoop).Select()

                Return True

            End If

        Next

        Return False

    End Function

    Public Function GetForm(ByVal FormUID As String) As SAPbouiCOM.Form

        Return GOD_Main.GOD_Application.Forms.Item(FormUID)

    End Function



#Region "Get Error Details"

    'To Get Error Description in SAP B1

    Private Sub updateLastErrorDetails(ByVal ErrorCode As Integer)

        strLastErrorCode = ErrorCode

        strLastError = GOD_Main.GOD_Company.GetLastErrorCode() & ":" & GOD_Main.GOD_Company.GetLastErrorDescription()

    End Sub

#End Region



#Region "Add Column"

    'Add User Defined Field to Table

    Private Sub addCol(ByVal strTab As String, ByVal strCol As String, ByVal strDesc As String, ByVal nType As Integer, Optional ByVal nEditSize As Integer = 10, Optional ByVal nSubType As Integer = 0)

        Dim oUFields As SAPbobsCOM.UserFieldsMD

        Dim nError As Integer

        oUFields = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

        oUFields.TableName = strTab

        oUFields.Name = strCol

        oUFields.Type = nType

        oUFields.SubType = nSubType

        oUFields.Description = strDesc

        oUFields.EditSize = nEditSize

        nError = oUFields.Add()

        System.Runtime.InteropServices.Marshal.ReleaseComObject(oUFields)

        GC.Collect()

        GC.WaitForPendingFinalizers()

    End Sub

#End Region



#Region "Create Table"

    'Create New User Defined Table

    Public Function CreateTable(ByVal TableName As String, ByVal TableDescription As String, ByVal TableType As SAPbobsCOM.BoUTBTableType) As Boolean

        Dim intRetCode As Integer

        Dim objUserTableMD As SAPbobsCOM.UserTablesMD

        objUserTableMD = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)

        Try

            If (Not objUserTableMD.GetByKey(TableName)) Then

                objUserTableMD.TableName = TableName

                objUserTableMD.TableDescription = TableDescription

                objUserTableMD.TableType = TableType

                intRetCode = objUserTableMD.Add()

                If (intRetCode = 0) Then

                    GOD_Main.GOD_Application.StatusBar.SetText(TableName & " Table is Created Successfully.", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_None)

                    Return True

                End If

            Else

                Return False

            End If

        Catch ex As Exception

            GOD_Main.GOD_Application.MessageBox(ex.Message)

        Finally

            System.Runtime.InteropServices.Marshal.ReleaseComObject(objUserTableMD)

            GC.Collect()

        End Try

    End Function

#End Region



#Region "Field Creations"

    'Add Alphabet Field to Table

    Public Sub AddAlphaField(ByVal TableName As String, ByVal ColumnName As String, ByVal ColDescription As String, ByVal Size As Integer, ByVal SubType As SAPbobsCOM.BoFldSubTypes, Optional ByVal DefaultValue As String = "")

        Try

            addField(TableName, ColumnName, ColDescription, SAPbobsCOM.BoFieldTypes.db_Alpha, Size, SAPbobsCOM.BoFldSubTypes.st_None, "", "", DefaultValue)

        Catch ex As Exception

            GOD_Main.GOD_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)

        End Try

    End Sub

    

    'Add Alpha Field to Table and add Validvalues and set Default Values

    Public Sub AddAlphaField(ByVal TableName As String, ByVal ColumnName As String, ByVal ColDescription As String, ByVal Size As Integer, ByVal ValidValues As String, ByVal ValidDescriptions As String, ByVal SetValidValue As String)

        Try

            addField(TableName, ColumnName, ColDescription, SAPbobsCOM.BoFieldTypes.db_Alpha, Size, SAPbobsCOM.BoFldSubTypes.st_None, ValidValues, ValidDescriptions, SetValidValue)

        Catch ex As Exception

            Throw ex

        End Try

    End Sub

    'To Add Field In Table 

    Public Sub addField(ByVal TableName As String, ByVal ColumnName As String, ByVal ColDescription As String, ByVal FieldType As SAPbobsCOM.BoFieldTypes, ByVal Size As Integer, ByVal SubType As SAPbobsCOM.BoFldSubTypes, ByVal ValidValues As String, ByVal ValidDescriptions As String, ByVal SetValidValue As String)

        Dim intLoop As Integer

        Dim strValue, strDesc As Array

        Dim objUserFieldMD As SAPbobsCOM.UserFieldsMD

        objUserFieldMD = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

        Try

            strValue = ValidValues.Split(Convert.ToChar(","))

            strDesc = ValidDescriptions.Split(Convert.ToChar(","))

            If (strValue.GetLength(0) <> strDesc.GetLength(0)) Then

                Throw New Exception("Invalid Valid Values")

            End If

            If (Not isColumnExist(TableName, ColumnName)) Then

                objUserFieldMD.TableName = TableName

                objUserFieldMD.Name = ColumnName

                objUserFieldMD.Description = ColDescription

                objUserFieldMD.Type = FieldType

                If (FieldType <> SAPbobsCOM.BoFieldTypes.db_Numeric) Then

                    objUserFieldMD.Size = Size

                Else

                    objUserFieldMD.EditSize = Size

                End If

                objUserFieldMD.SubType = SubType

                If strValue.Length > 1 Then

                    For intLoop = 0 To strValue.GetLength(0) - 1

                        objUserFieldMD.ValidValues.Value = strValue(intLoop)

                        objUserFieldMD.ValidValues.Description = strDesc(intLoop)

                        objUserFieldMD.ValidValues.Add()

                    Next

                    objUserFieldMD.DefaultValue = SetValidValue

                Else

                    If SetValidValue.Length > 0 Then

                        objUserFieldMD.DefaultValue = SetValidValue

                    End If

                End If

                If (objUserFieldMD.Add() <> 0) Then

                    GOD_Main.GOD_Application.StatusBar.SetText(GOD_Main.GOD_Company.GetLastErrorDescription & " For UDF " & ColumnName & " in Table " & TableName)

                Else

                    GOD_Main.GOD_Application.StatusBar.SetText(ColumnName + "Field Created Successfully in Table ." & TableName, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_None)

                End If

            End If

        Catch ex As Exception

            GOD_Main.GOD_Application.StatusBar.SetText(ex.Message & " For UDF " & ColumnName & " in Table " & TableName, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)

        Finally

            System.Runtime.InteropServices.Marshal.ReleaseComObject(objUserFieldMD)

            GC.Collect()

        End Try

    End Sub

    

    'To Add Date Field

    Public Sub AddDateField(ByVal TableName As String, ByVal ColumnName As String, ByVal ColDescription As String, ByVal SubType As SAPbobsCOM.BoFldSubTypes)

        Try

            addField(TableName, ColumnName, ColDescription, SAPbobsCOM.BoFieldTypes.db_Date, 0, SubType, "", "", "")

        Catch ex As Exception

            GOD_Main.GOD_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)

        End Try

    End Sub

#End Region



#Region " Column Exist or Not "

    'To Verify the Given Field already Exists or not

    Private Function isColumnExist(ByVal TableName As String, ByVal ColumnName As String) As Boolean

        Dim objRecordSet As SAPbobsCOM.Recordset

        Dim strTemp As String = ""

        objRecordSet = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

        Try

            strTemp = "SELECT COUNT(*) FROM CUFD WHERE TableID = '" & TableName & "' AND AliasID = '" & ColumnName & "'"

            objRecordSet.DoQuery(strTemp)

            If (Convert.ToInt16(objRecordSet.Fields.Item(0).Value) = 0) Then

                Return False

            Else

                Return True

            End If

        Catch ex As Exception

            Throw ex

        Finally

            System.Runtime.InteropServices.Marshal.ReleaseComObject(objRecordSet)

            GC.Collect()

        End Try

    End Function

#End Region



#Region "LOAD MENU"

    'To Load Menu Item in SAP Business One Using XML

    Public Sub LoadMenu(ByVal XMLFile As String)

        Dim oXML As System.Xml.XmlDocument

        Dim strXML As String

        Try

            oXML = New System.Xml.XmlDocument

            oXML.Load(XMLFile)

            strXML = oXML.InnerXml()

            GOD_Main.GOD_Application.LoadBatchActions(strXML)

        Catch ex As Exception

            GOD_Main.GOD_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)

        End Try

    End Sub

#End Region



    Protected Overrides Sub Finalize()

        MyBase.Finalize()

    End Sub

End Class



Public Enum ResourceType

    Embeded

    Content

End Enum






 

5. ChooseFromList Class Code

 

Imports System.Reflection



Public Class clsChooseFromList

#Region "Declarations"

    Public Shared ItemUID As String

    Public Shared SourceFormUID As String

    Public Shared CFLChoice As String

    Private Ouserdatasource As SAPbouiCOM.UserDataSource

    Private oedit As SAPbouiCOM.EditText

    Private oForm As SAPbouiCOM.Form

    Private GOD_Matrix As SAPbouiCOM.Grid

    Private oItem As SAPbouiCOM.Item

    Private objGrid As SAPbouiCOM.Grid

    Private dtTemp As SAPbouiCOM.DataTable

    Private strSelectedItem1 As String = String.Empty

    Private strSelectedItem2 As String = String.Empty

    Public Shared oDBs_DetailCont As SAPbouiCOM.DBDataSource

    Public Shared oDBs_DetailChrg As SAPbouiCOM.DBDataSource

    Public SourceMatrixRow As String

    Private referencedFormUID As String

    Public oUDS As SAPbouiCOM.UserDataSource

    Dim oformidTxt As SAPbouiCOM.EditText

    Public intColSel As Integer = 0

#End Region



#Region "New"

    Public Sub New()

    End Sub

#End Region



#Region "Bind Data"

    Public Sub databound(ByVal GOD_Form As SAPbouiCOM.Form, ByVal SourceForm As SAPbouiCOM.Form, ByVal oDBs_Detail1 As SAPbouiCOM.DBDataSource, ByVal oDBs_Detail2 As SAPbouiCOM.DBDataSource, ByVal Row As String, SourceRowNo1 As Integer)

        Try

            Dim GOD_OMQL_RecMenu As SAPbobsCOM.Recordset

            GOD_OMQL_RecMenu = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

            Dim strSQL As String = ""

            oDBs_DetailCont = oDBs_Detail1

            oDBs_DetailChrg = oDBs_Detail2

            SourceMatrixRow = Row



            oUDS = GOD_Form.DataSources.UserDataSources.Add("UDS1", SAPbouiCOM.BoDataType.dt_LONG_TEXT, 20)

            oformidTxt = GOD_Form.Items.Item("6").Specific

            oformidTxt.DataBind.SetBound(True, "", "UDS1")

            oformidTxt.Value = SourceForm.UniqueID

            referencedFormUID = SourceForm.UniqueID



            GOD_Form.Freeze(True)

            GOD_Form.DataSources.DataTables.Add("dtLevel3")

            Ouserdatasource = GOD_Form.DataSources.UserDataSources.Add("dbFind", SAPbouiCOM.BoDataType.dt_LONG_TEXT, 250)

            oedit = GOD_Form.Items.Item("etFind").Specific

            oedit.DataBind.SetBound(True, "", "dbFind")

            objGrid = GOD_Form.Items.Item("mtchoose").Specific

            dtTemp = GOD_Form.DataSources.DataTables.Item("dtLevel3")

            If (CFLChoice = "CFL_Vendor_SimpleForm" Or CFLChoice = "CFL_Customer_SimpleForm") Then

                If (CFLChoice = "CFL_Customer_SimpleForm") Then

                    strSQL = "Select CardCode as 'SAP Code',CardName 'Vendor Name',CardCode 'Vendor Code',Balance 'Vendor Balance' From OCRD Where CardType = 'C' Order By CardCode"

                Else

                    strSQL = "Select CardCode as 'SAP Code',CardName 'Vendor Name',CardCode 'Vendor Code',Balance 'Vendor Balance' From OCRD Where CardType = 'S' Order By CardCode"

                End If

                GOD_Form.Title = "List Of Business Partners"

                dtTemp.ExecuteQuery(strSQL)

                If dtTemp.IsEmpty = True Then

                    GOD_Main.GOD_Application.SetStatusBarMessage("No Matching Business Partners Records Found.", SAPbouiCOM.BoMessageTime.bmt_Short, True)

                    GOD_Form.Close()

                    Exit Sub

                End If

                objGrid.DataTable = dtTemp

                objGrid.Columns.Item(0).TitleObject.Caption = "SAP Code"

                objGrid.Columns.Item(1).TitleObject.Caption = "BP Code"

                objGrid.Columns.Item(2).TitleObject.Caption = "BP Name"

                objGrid.Columns.Item(3).TitleObject.Caption = "BP Balance"

            End If

            objGrid.Columns.Item(0).Visible = False

            objGrid.AutoResizeColumns()

            objGrid.SelectionMode = SAPbouiCOM.BoMatrixSelect.ms_Single

            If objGrid.Rows.Count > 0 Then

                objGrid.Rows.SelectedRows.Add(0)

            End If

            GOD_Matrix = GOD_Form.Items.Item("mtchoose").Specific

            GOD_Form.Freeze(False)

            GOD_Form.Update()

        Catch ex As Exception

            GOD_Main.GOD_Application.MessageBox(ex.Message)

        Finally

        End Try

    End Sub

#End Region





#Region "LOAD CFL"

    Public Sub LoadCFLvalues(ByRef pVal As SAPbouiCOM.ItemEvent)

        oForm = GetForm(pVal.FormUID)

        oItem = oForm.Items.Item("mtchoose")

        GOD_Matrix = CType(oItem.Specific, SAPbouiCOM.Grid)

        Dim inti As Integer

        inti = 0

        Dim sandy As SAPbouiCOM.SelectedRows = GOD_Matrix.Rows.SelectedRows()

        Dim intRowId As Integer = sandy.Item(0, SAPbouiCOM.BoOrderType.ot_SelectionOrder)

        If (CFLChoice = "CFL_Vendor_SimpleForm" Or CFLChoice = "CFL_Customer_SimpleForm") Then

            strSelectedItem1 = Convert.ToString(GOD_Matrix.DataTable.GetValue(2, intRowId))

            strSelectedItem2 = Convert.ToString(GOD_Matrix.DataTable.GetValue(1, intRowId))

        End If



        oForm.Close()

        oForm = GetForm(SourceFormUID)

        oForm = GOD_Main.objUtilities.GetForm(referencedFormUID)

         If (CFLChoice = "CFL_Vendor_SimpleForm" Or CFLChoice = "CFL_Customer_SimpleForm") Then

            oForm.Items.Item("edVendorNm").Specific.value = strSelectedItem1

            oForm.Items.Item("edVendorCd").Specific.value = strSelectedItem2

            oForm.Items.Item("edVendorNm").Click(SAPbouiCOM.BoCellClickType.ct_Regular)

        End If

        strSelectedItem1 = ""

        strSelectedItem2 = ""

    End Sub

#End Region



#Region "Check for UDO Exists"

    Public Function UDOExists(ByVal code As String) As Boolean

        GC.Collect()

        Dim v_UDOMD As SAPbobsCOM.UserObjectsMD

        Dim v_ReturnCode As Boolean

        v_UDOMD = GOD_Main.objUtilities.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD)

        v_ReturnCode = v_UDOMD.GetByKey(code)

        System.Runtime.InteropServices.Marshal.ReleaseComObject(v_UDOMD)

        v_UDOMD = Nothing

        Return v_ReturnCode

    End Function

#End Region



#Region "CFL Form"

    Public Sub CFLForm(ByVal strSQL As String, ByVal dtTemp As SAPbouiCOM.DataTable, ByVal objGrid As SAPbouiCOM.Grid, ByVal strTitle As String, ByVal GOD_Form As SAPbouiCOM.Form)

        GOD_Form.Title = strTitle

        dtTemp.ExecuteQuery(strSQL)

        objGrid.DataTable = dtTemp

        objGrid.Columns.Item(0).TitleObject.Caption = "SAP No."

        objGrid.Columns.Item(1).TitleObject.Caption = "Code"

        objGrid.Columns.Item(2).TitleObject.Caption = "Name"

        objGrid.Columns.Item(3).TitleObject.Caption = "Test Name"

    End Sub

#End Region



#Region "Get Form"

    Public Function GetForm(ByVal FormUID As String) As SAPbouiCOM.Form

        Return GOD_Main.GOD_Application.Forms.Item(FormUID)

    End Function

#End Region



#Region "Item Event"

    Public Sub ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean)

        BubbleEvent = True

        If (pVal.FormTypeEx = "CFLHeader" Or pVal.FormTypeEx = "CFLDetail") Then 'Or pVal.FormTypeEx = "CFL_FLD_FTYPE_HDR" Or pVal.FormTypeEx = "CFL_FLD_CODE_HDR") Then

            If pVal.Before_Action = True Then

                If pVal.ItemUID = "mtchoose" Then

                    If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CLICK Then

                        oForm = GetForm(pVal.FormUID)

                        oItem = CType(oForm.Items.Item(pVal.ItemUID), SAPbouiCOM.Item)

                        GOD_Matrix = CType(oItem.Specific, SAPbouiCOM.Grid)

                        For i As Integer = 1 To GOD_Matrix.Rows.Count - 1

                            If GOD_Matrix.Rows.IsSelected(i) = True Then

                                If pVal.Row > 0 Then

                                    GOD_Matrix.Rows.SelectedRows.Add(pVal.Row)

                                End If

                            End If

                        Next

                    End If

                    If pVal.EventType = SAPbouiCOM.BoEventTypes.et_DOUBLE_CLICK Then

                        oForm = GetForm(pVal.FormUID)

                        referencedFormUID = oForm.Items.Item("6").Specific.value

                        oItem = CType(oForm.Items.Item(pVal.ItemUID), SAPbouiCOM.Item)

                        GOD_Matrix = CType(oItem.Specific, SAPbouiCOM.Grid)

                        GOD_Main.strColSelectedinCFL = pVal.ColUID

                        If pVal.Row > 0 Then

                            GOD_Matrix.Rows.SelectedRows.Add(pVal.Row)

                            LoadCFLvalues(pVal)

                        End If

                    End If

                End If

            End If

        End If

        If pVal.FormTypeEx = "CFLHeader" And pVal.BeforeAction = False And pVal.ItemUID = "btnNew" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then

            oForm = GetForm(pVal.FormUID)

            If oForm.Title = "List Of Clients" Then

                GOD_Main.GOD_Application.ActivateMenuItem("2561")

                oForm.Close()

                Dim GOD_OMQL_ItemForm As SAPbouiCOM.Form

                GOD_OMQL_ItemForm = GOD_Main.GOD_Application.Forms.GetFormByTypeAndCount("134", pVal.FormTypeCount)

                GOD_OMQL_ItemForm.Mode = SAPbouiCOM.BoFormMode.fm_ADD_MODE

            ElseIf oForm.Title = "List Of Matching Numbers." Then

                Dim GOD_OMQL_RecMenu As SAPbobsCOM.Recordset

                GOD_OMQL_RecMenu = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

                GOD_OMQL_RecMenu.DoQuery("SELECT MenuUid FROM (SELECT (RANK() OVER (ORDER BY TableName)) + 51200 AS MenuUid, TableName, Descr FROM OUTB WHERE ObjectType = 0) T0  WHERE TableName = 'GOD_OMAT'")

                GOD_Main.GOD_Application.ActivateMenuItem(GOD_OMQL_RecMenu.Fields.Item("MenuUid").Value)

                oForm.Close()

            End If

        End If



        If pVal.FormTypeEx = "CFLDetail" And pVal.BeforeAction = False And pVal.ItemUID = "btnNew" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then

            oForm = GetForm(pVal.FormUID)

            If oForm.Title = "List Of Items" Then

                GOD_Main.GOD_Application.ActivateMenuItem("3073")

                oForm.Close()

                Dim GOD_OMQL_ItemForm As SAPbouiCOM.Form

                GOD_OMQL_ItemForm = GOD_Main.GOD_Application.Forms.GetFormByTypeAndCount("150", pVal.FormTypeCount)

                GOD_OMQL_ItemForm.Mode = SAPbouiCOM.BoFormMode.fm_ADD_MODE

            ElseIf oForm.Title = "List Of Matching Numbers." Then

                Dim GOD_OMQL_RecMenu As SAPbobsCOM.Recordset

                GOD_OMQL_RecMenu = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

                GOD_OMQL_RecMenu.DoQuery("SELECT MenuUid FROM (SELECT (RANK() OVER (ORDER BY TableName)) + 51200 AS MenuUid, TableName, Descr FROM OUTB WHERE ObjectType = 0) T0  WHERE TableName = 'GOD_OMAT'")

                GOD_Main.GOD_Application.ActivateMenuItem(GOD_OMQL_RecMenu.Fields.Item("MenuUid").Value)

                oForm.Close()

            End If

        End If

        If pVal.ItemUID = "btnChoose" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then

            oForm = GetForm(pVal.FormUID)

            referencedFormUID = oForm.Items.Item("6").Specific.value

            LoadCFLvalues(pVal)

        End If

        If pVal.BeforeAction = False Then

            If pVal.EventType = SAPbouiCOM.BoEventTypes.et_KEY_DOWN Then

                'For selecting the specific row according to search

                Try

                    oForm = GetForm(pVal.FormUID)

                    Dim objGrid As SAPbouiCOM.Grid

                    Dim oedit As SAPbouiCOM.EditText

                    If pVal.ItemUID = "etFind" Then

                        If Not (pVal.CharPressed = "13" Or pVal.CharPressed = "40" Or pVal.CharPressed = "38") Then

                            Dim i, j As Integer

                            Dim strItem As String

                            objGrid = oForm.Items.Item("mtchoose").Specific

                            oedit = oForm.Items.Item("etFind").Specific

                            For intColSel = 0 To objGrid.Columns.Count - 1

                                If objGrid.Columns.Item(intColSel).TitleObject.Caption = GOD_Main.strColSelectedinCFL Then

                                    Exit For

                                End If

                            Next

                            For i = 0 To objGrid.DataTable.Rows.Count - 1

                                strItem = ""

                                If intColSel = 0 Then

                                    strItem = objGrid.DataTable.GetValue(1, i)

                                Else

                                    strItem = objGrid.DataTable.GetValue(intColSel, i)

                                End If

                                If (oedit.String.Length = 0) Then

                                    Exit For

                                End If

                                For j = 1 To oedit.String.Length

                                    If oedit.String.Length <= strItem.Length Then

                                        If strItem.Substring(0, j).ToUpper = oedit.String.ToUpper Then

                                            objGrid.Rows.SelectedRows.Add(i)

                                            Exit Try

                                        End If

                                    End If

                                Next

                            Next

                            intColSel = 0

                        End If

                    End If

                Catch ex As Exception

                    MessageBox.Show(ex.Message)

                End Try

                Try

                    oForm = GetForm(pVal.FormUID)

                    oItem = oForm.Items.Item("mtchoose")

                    GOD_Matrix = oForm.Items.Item("mtchoose").Specific

                    If (pVal.CharPressed = 40) Then

                        Dim currentRow As Integer

                        For intLoop As Integer = 0 To GOD_Matrix.DataTable.Rows.Count - 1

                            If (GOD_Matrix.Rows.IsSelected(intLoop) = True) Then

                                currentRow = intLoop

                                Exit For

                            End If

                        Next

                        Dim iRowcount As Integer = GOD_Matrix.Rows.Count

                        If currentRow < iRowcount - 1 Then

                            GOD_Matrix.Columns.Item("RowsHeader").Click(currentRow + 1, False)

                        End If

                    End If



                    If (pVal.CharPressed = 38) Then

                        Dim currentRow As Integer

                        For intLoop As Integer = 0 To GOD_Matrix.DataTable.Rows.Count - 1

                            If (GOD_Matrix.Rows.IsSelected(intLoop) = True) Then

                                currentRow = intLoop

                                Exit For

                            End If

                        Next

                        Dim iRowcount As Integer = GOD_Matrix.Rows.Count

                        If currentRow > 0 Then

                            GOD_Matrix.Columns.Item("RowsHeader").Click(currentRow - 1, False)

                        End If

                    End If

                Catch ex As Exception

                    MessageBox.Show(ex.Message)

                End Try

            End If

        End If

    End Sub

#End Region



End Class




Kindly Find attached "Solution Explorer" Structure for you reference.

I will Upgrade this Blog with Complex Form Application Also.

Revert For Any Clarification.

Thanks and Regards,
Mahendrakumar







Keep learning and keep growing. Have a great weekend.

To get Free Full Course SAP B1 Technical and SAP B1 Functional, checkout and subscribe to our YouTube Channel today.

Keep learning and keep growing. https://lnkd.in/gi62G4wT

and don't forget to hit the BELL icon to Get notified every time we Upload a New Video.

Like this post? Want to see more?

 🔔 Ring it on my Profile

 📌 Subscribe to our YouTube channel: SAPB1TechnicalTrainingByMahi

 📌 Follow our LinkedIn Learner community, mahendrakumardp

 ❤️ #SAPB1TechnicalTrainingByMahi

#TheBestRun #SAP #SAPBusinessOne #SAPB1Training #saptutorial #innovation #management #humanresources #digitalmarketing #technology #sapb1 #Empowerment #GrowthMindset #india #entrepreneurs #SAPB1Training #saptutorial #innovation #management #humanresources #digitalmarketing #technology #sapb1 #b1
 

25 Comments
Labels in this area