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
7,545
Hello Guys,

Greetings !!!

Kindly Find the Attached Procedure Step By Step to Creating UDF,UDT and Registering UDO in SAP Business One System Forms.

  1. Creating User Defined Fields

  2. Creating User Defined Tables

  3. Registering User Defined Objects


 

Your Source Code Template Must be Same as  Follows   https://blogs.sap.com/2017/08/03/simple-sap-b1-add-on-for-beginners/

  • To Create User Defined Tables : There are Six Types Of Tables in SAP Business One. NoObject,Document,DocumentLines,MasterData and MasterDataLines. Call Following Function in Class Main.


objUtilities.CreateTable("GOD_QCGR", "GOD Groups", SAPbobsCOM.BoUTBTableType.bott_NoObject) 

 

Just Change the Type Of Parameter to Table Type. CreateTable Function Will be as Follows. Define CreateTable Function in Utilities Class
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.SetStatusBarMessage(TableDescription & " User Defined Table Successfully.", SAPbouiCOM.BoMessageTime.bmt_Short, False)
Return True
Else
GOD_Main.GOD_Application.SetStatusBarMessage(TableDescription & " Failed To Creat User Defined Table.", SAPbouiCOM.BoMessageTime.bmt_Short, 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

 

  • For Adding Fields in User Defined No Object Table GOD_OCGR Use Following Functions For

  • We Can Add Alphanumeric,Date,Quantity and all type Of User Defined Fields in System Table and User Defined Tables also

  • I have Created 3 Types of Tables - 1.Np Object Type Table. 2.Document Type and 3. Master Type Of Table

  • Registering of User Defined Table also done in Following Code


Class Main Code will be as Follows

 
Imports System.Reflection
Imports System.Diagnostics
Imports System.Net.Mail
Imports System.Net
Imports System.Text
Imports SAPbobsCOM

Public Class clsMain

#Region "Declaration"
Dim objChooseForm As SAPbouiCOM.Form

Public WithEvents GOD_Application As SAPbouiCOM.Application
Public strGetManifestResourceStreamName As String = "GOD_QC_Addon"
Public GOD_Company As SAPbobsCOM.Company
Public SourceRowNo1 As Integer
'Creating Instances For Each Class

Public objUtilities As clsUtilities
Public objItemMaster As clsItemMaster
Public LastErrorDescription As String
Public LastErrorCode As Integer

'System Forms
Public QueryXML As New Xml.XmlDocument
Public objChoose As clsChooseFromList
Public strVariant As String = ""
Public strMenuClicked As String = ""
Public strTmp As String = ""
Public GOD_SourceForm As SAPbouiCOM.Form
Public GOD_Static As SAPbouiCOM.StaticText
Public GOD_Rec As SAPbobsCOM.Recordset
'For UI
Public GOD_Matrix As SAPbouiCOM.Matrix
Public GOD_Edit As SAPbouiCOM.EditText
Public GOD_Item As SAPbouiCOM.Item
Public GOD_Combo As SAPbouiCOM.ComboBox
Private referencedFormUID As String
'For DI
Public oDBs_Head As SAPbouiCOM.DBDataSource
Public oDBs_Detail As SAPbouiCOM.DBDataSource
'Objects
Public GOD_ChkBox As SAPbouiCOM.CheckBox
Public GOD_Column1 As SAPbouiCOM.ColumnTitle
Public isAddConnected As Boolean = False
Public GOD_RS As SAPbobsCOM.Recordset
Public oRec As SAPbobsCOM.Recordset
Public str As String = ""
Public strTemp As String = ""
'For Updating Sub User Details in SAP Activity Master
Dim sCode As String = ""
'For Sending Internal Messages in SAP Business one
Public oCmpSrv As SAPbobsCOM.CompanyService
Public oMessageService As MessagesService
#End Region

#Region "New"
Public Sub New()
'Object Initialization 19042017 - Mahendrakumar
objUtilities = New clsUtilities
objItemMaster = New clsItemMaster
End Sub
#End Region

#Region "Initialise"
Public Function Initialise() As Boolean
GOD_Application = objUtilities.GetApplication()
objUtilities.ShowSuccessMessage("Please wait for the System Form Manipulation Addon Icon to appear in menu. It may take few minutes based on Server and Network speed.")
GOD_Company = objUtilities.GetCompany(GOD_Application)
Call CreateTables()
Call createObjects()
objUtilities.ShowSuccessMessage("System Form Manipulation Add-on Connected. You may now proceed to use addon.")
Return True
End Function
#End Region

#Region "Create Objects"
Private Sub createObjects()
objChoose = New clsChooseFromList
End Sub
#End Region


#Region "Register UDO"
Private Sub RegisterUDO()
'For Document Type Table
Dim findAliasNDescription = New String(,) {{"DocEntry", "DocEntry"}} 'For Find in Default Form - DocEntry Column
findAliasNDescription = New String(,) {{"DocEntry", "DocEntry"}}
If Not objUtilities.UDOExists("GOD_OQCG") = True Then
objUtilities.registerUDO("GOD_OQCG", "GOD QC Master", SAPbobsCOM.BoUDOObjType.boud_Document, findAliasNDescription, "GOD_OQCG", "GOD_QCG1", "", "", "", "", "", "", "", SAPbobsCOM.BoYesNoEnum.tNO)
End If

'For Master Data Type Table Registration
findAliasNDescription = New String(,) {{"Code", "Code"}} 'For Find in Default Form - Code and Name For Master Type Of User Defined Table
If Not objUtilities.UDOExists("GOD_OREC") = True Then
objUtilities.registerUDO("GOD_OREC", "GOD Receiver", SAPbobsCOM.BoUDOObjType.boud_MasterData, findAliasNDescription, "GOD_OREC", "GOD_REC1", "", "", "", "", "", "", "", SAPbobsCOM.BoYesNoEnum.tNO)
End If
End Sub
#End Region
Public Sub CLFHeader(ByVal ItemUID As String, ByVal FormUID As String, ByVal CFLName As String, ByVal FormTypeEx As String)
clsChooseFromList.ItemUID = ItemUID
clsChooseFromList.SourceFormUID = FormUID
clsChooseFromList.CFLChoice = CFLName
Dim objChooseForm As SAPbouiCOM.Form
If objUtilities.FormExist(FormTypeEx) = True Then
'Do Nothing
Else
GOD_Main.objUtilities.LoadForm("GOD_CFLHeader.xml", "GOD_CFLHeader", "GOD_CFLHeader", ResourceType.Embeded)
objChooseForm = GOD_Main.GOD_Application.Forms.ActiveForm
objChoose.databound(objChooseForm, GOD_SourceForm, oDBs_Detail, oDBs_Detail, "", SourceRowNo1)
End If
End Sub

#Region "Create Table"
Public Sub CreateTables()
Try
'No Object Type Table
objUtilities.CreateTable("GOD_OMGF", "GOD Mgf Catalog No", SAPbobsCOM.BoUTBTableType.bott_NoObject)

'Document Type Table
objUtilities.CreateTable("GOD_OQCG", "GOD QC Master", SAPbobsCOM.BoUTBTableType.bott_Document)
objUtilities.CreateTable("GOD_QCG1", "GOD QC Master-Rows", SAPbobsCOM.BoUTBTableType.bott_DocumentLines)

'Master Data Table
objUtilities.CreateTable("GOD_OREC", "GOD Receiver", SAPbobsCOM.BoUTBTableType.bott_MasterData)
objUtilities.CreateTable("GOD_REC1", "GOD Receiver-Rows", SAPbobsCOM.BoUTBTableType.bott_MasterDataLines)

'Adding Fields in System Table -e.g. Item Master
objUtilities.AddAlphaField("OITM", "Instrmnt", "Instrument", 1)

'Adding Fields in User Defined Table
objUtilities.AddFloatField("@GOD_OQCG", "Qty", "Qty", BoFldSubTypes.st_Quantity)
objUtilities.AddDateField("@GOD_OQCG", "QCDate", "QC 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 "GOD_CFLHeader" 'For Choose From List at Header Level
objChoose.ItemEvent(FormUID, pVal, BubbleEvent)
Case "GOD_CFLDetail" 'For Choose From List At Detail Level
objChoose.ItemEvent(FormUID, pVal, BubbleEvent)
Case "150" 'For Item Master Item Event Calling
objItemMaster.ItemEvent(FormUID, pVal, BubbleEvent)
End Select
Catch ex As Exception
GOD_Application.MessageBox(ex.Message)
End Try
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) Then
CloseApp()
End If
End Sub
#End Region

End Class




 

Class Utitilies Will be as Follows

 
Imports System.Reflection
Public Class clsUtilities
Public strLastErrorCode As String
Public strLastError As String
Public GOD_Form As SAPbouiCOM.Form
Public objEdit As SAPbouiCOM.EditText
Public strAddMenu As String = ""
Private strThousSep As String = ","
Private strDecSep As String = "."
Private intQtyDec As Integer = 3
Private objForm As SAPbouiCOM.Form
Dim GOD_RecSet As SAPbobsCOM.Recordset
Dim Crores, Lakhs, Rupees, Paise, Temp
Dim DecimalPlace As Long, Count As Long
Dim myLakhs, myCrores As String
Dim Place(9) As String
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
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

Public Sub AddFloatField(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_Float, 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

Public Sub AddNumericField(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 DefultValue As String)
Try
addField(TableName, ColumnName, ColDescription, SAPbobsCOM.BoFieldTypes.db_Numeric, Size, SAPbobsCOM.BoFldSubTypes.st_None, ValidValues, ValidDescriptions, DefultValue)
Catch ex As Exception
GOD_Main.GOD_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
End Try
End Sub

Public Sub AddNumericField(ByVal TableName As String, ByVal ColumnName As String, ByVal ColDescription As String, ByVal Size As Integer)
Try
addField(TableName, ColumnName, ColDescription, SAPbobsCOM.BoFieldTypes.db_Numeric, Size, SAPbobsCOM.BoFldSubTypes.st_None, "", "", "")
Catch ex As Exception
GOD_Main.GOD_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
End Try
End Sub

Public Sub addFieldWithLinkedTable(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 LinkedTableName As String, ByVal EditSize As Integer)
Dim objUserFieldMD As SAPbobsCOM.UserFieldsMD
objUserFieldMD = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
Try
If (Not isColumnExist(TableName, ColumnName)) Then
objUserFieldMD.Name = ColumnName
objUserFieldMD.Type = FieldType
objUserFieldMD.EditSize = 8
objUserFieldMD.Description = ColDescription
objUserFieldMD.SubType = SubType
objUserFieldMD.LinkedTable = LinkedTableName
objUserFieldMD.TableName = TableName
If (objUserFieldMD.Add() <> 0) Then
GOD_Main.GOD_Application.StatusBar.SetText(GOD_Main.GOD_Company.GetLastErrorDescription)
End If
End If
Catch ex As Exception
GOD_Main.GOD_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
Finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(objUserFieldMD)
GC.Collect()
End Try
End Sub
#Region "Create 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.objUtilities.ShowSuccessMessage(TableName & " Table Created Successfully.")
Return True
Else
GOD_Main.objUtilities.ShowSuccessMessage(TableName & " Table Not Created Successfully.")
Return False
End If
Else
Return False
End If
Catch ex As Exception
GOD_Main.GOD_Application.StatusBar.SetText(TableName & " Table is not Created Successfully." & ex.Message)
Finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(objUserTableMD)
GC.Collect()
End Try
End Function
#End Region

Public Function FormExistTypeEx(ByVal FormUID As String) As Boolean
Dim intLoop As Integer
For intLoop = GOD_Main.GOD_Application.Forms.Count - 1 To 0 Step -1
If Trim(FormUID) = Trim(GOD_Main.GOD_Application.Forms.Item(intLoop).TypeEx) Then
Return True
End If
Next
Return False
End Function

#Region "GetApplication"
'To Get SAP Business One Application
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

#Region "GET COMPANY"
'To Connect to SAP SAP Business One 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 Quality Control 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"
'*****************************************************************
'Type : Function
'Name : registerUDO
'Parameter : UDOCode,UDOName,UDOType,findAliasNDescription,parentTableName,childTable1,childTable2,childTable3,childTable4,LogOption,DefFormOption,MenuItem,MenuCaption,FatherMenuId,Position
'Return Value : Boolean
'Author : Mahendrakumar
'Created Date : 21042017
'Last Modified By :
'Modified Date :
'Purpose : 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"
'Purpose : 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

#Region "Add Column"
'Purpose : 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()
If nError <> 0 Then
'MsgBox(strCol & " table could not be added")
End If
End Sub
#End Region

#Region "Field Creations"
'Purpose : 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

'Purpose : Add Field to 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)
Else
GOD_Main.GOD_Application.StatusBar.SetText(objUserFieldMD.Name + " Created Successfully.", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_None)
End If
End If
Catch ex As Exception
GOD_Main.GOD_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
Finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(objUserFieldMD)
GC.Collect()
End Try
End Sub
#End Region

#Region " Column Exist 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 "DI /UI Methods"
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("BSPL_Beam_Manufacturing." + 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
#Region "GetDateTime"
Public Function GetDateTimeValue(ByVal DateString As String) As DateTime
Dim objBridge As SAPbobsCOM.SBObob
objBridge = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge)
Return objBridge.Format_StringToDate(DateString).Fields.Item(0).Value
End Function
Public Function GetDateToString(ByVal DateString As String) As DateTime
Dim objBridge As SAPbobsCOM.SBObob
objBridge = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge)
Return objBridge.Format_DateToString(DateString).Fields.Item(0).Value
End Function
Public Function GetSBODateString(ByVal DateVal As DateTime) As String
Dim objBridge As SAPbobsCOM.SBObob
objBridge = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge)
Return objBridge.Format_DateToString(DateVal).Fields.Item(0).Value
End Function
#End Region

#Region "Number Conversions"
Public Function GetQtyValue(ByVal QtyString As String) As Double
Dim dblValue As Double
QtyString = QtyString.Replace(strThousSep, "")
QtyString = QtyString.Replace(strDecSep, System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)
dblValue = Convert.ToDouble(QtyString)
Return dblValue
End Function
Public Function GetQtyString(ByVal QtyVal As Double) As String
GetQtyString = QtyVal.ToString()
GetQtyString.Replace(",", strDecSep)
End Function
#End Region

#Region "Business Objects"
Public Function GetBusinessObject(ByVal ObjectType As SAPbobsCOM.BoObjectTypes) As Object
Return GOD_Main.GOD_Company.GetBusinessObject(ObjectType)
End Function

#Region "Filling the values in the Combo"
Public Sub FillDocvalues(ByVal GOD_Form As SAPbouiCOM.Form, ByVal comboid As String)
Dim oRS As SAPbobsCOM.Recordset = GOD_Main.objUtilities.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
Dim objCombo As SAPbouiCOM.ComboBox
oRS.DoQuery("Select Code, Name from [@FCA_DOC]")
objCombo = GOD_Form.Items.Item(comboid).Specific
If (objCombo.ValidValues.Count <= 0) Then
For i As Integer = 0 To oRS.RecordCount - 1
objCombo.ValidValues.Add(oRS.Fields.Item(0).Value, oRS.Fields.Item(1).Value)
oRS.MoveNext()
Next
End If
Dim objItem As SAPbouiCOM.Item = GOD_Form.Items.Item(comboid)
objItem.DisplayDesc = True
End Sub
#End Region

Public Function CreateUIObject(ByVal Type As SAPbouiCOM.BoCreatableObjectType) As Object
Return GOD_Main.GOD_Application.CreateObject(Type)
End Function

#End Region

#Region "Form Objects"
Public Function GetForm(ByVal FormUID As String) As SAPbouiCOM.Form
Return GOD_Main.GOD_Application.Forms.Item(FormUID)
End Function
Public Function GetForm(ByVal Type As String, ByVal Count As Integer) As SAPbouiCOM.Form
Return GOD_Main.GOD_Application.Forms.GetForm(Type, Count)
End Function
#End Region

#Region "GetEditTextValue"
Public Function GetEditText(ByVal aForm As SAPbouiCOM.Form, ByVal aUID As String) As String
objEdit = aForm.Items.Item(aUID).Specific
Return Convert.ToString(objEdit.Value)
End Function
Public Function GetEditText(ByVal aFormUID As String, ByVal aUID As String) As String
GOD_Form = GOD_Main.GOD_Application.Forms.Item(aFormUID)
objEdit = GOD_Form.Items.Item(aUID).Specific
Return Convert.ToString(objEdit.Value)
End Function
#End Region

#Region "SetEditTextValue"
Public Sub SetEditText(ByVal aForm As SAPbouiCOM.Form, ByVal aUID As String, ByVal aVal As String)
objEdit = aForm.Items.Item(aUID).Specific
objEdit.Value = aVal
End Sub
Public Sub SetEditText(ByVal aFormUID As String, ByVal aUID As String, ByVal aVal As String)
GOD_Form = GOD_Main.GOD_Application.Forms.Item(aFormUID)
objEdit = GOD_Form.Items.Item(aUID).Specific
objEdit.Value = aVal
End Sub
#End Region
#End Region
Public Function GetCode(ByVal sTableName As String) As String
Dim oRecSet As SAPbobsCOM.Recordset
Dim sQuery As String
oRecSet = GOD_Main.GOD_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
sQuery = "SELECT Top 1 Code FROM " & sTableName + " ORDER BY Convert(Int,Code) desc"
oRecSet.DoQuery(sQuery)
If Not oRecSet.EoF Then
GetCode = Convert.ToInt32(oRecSet.Fields.Item(0).Value.ToString()) + 1
Else
GetCode = "1"
End If
End Function
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
Public Function FormExist(ByVal FormUID As String) As Boolean
Dim intLoop As Integer
For intLoop = GOD_Main.GOD_Application.Forms.Count - 1 To 0 Step -1
If Trim(FormUID) = Trim(GOD_Main.GOD_Application.Forms.Item(intLoop).UniqueID) Then
Return True
End If
Next
Return False
End Function

End Class

Public Enum ResourceType
Embeded
Content
End Enum



 

Thanks and Regards,

Mahendrakumar
Labels in this area