Welcome Notes

Welcome Viewers
Showing posts with label SAP Business One Controls. Show all posts
Showing posts with label SAP Business One Controls. Show all posts

14 March 2018

Add Menu through SDK

Dear All,
   Today , We will see, How to Add Menu through SDK.



 Public Sub AddMenu(ByVal SBO_Application As SAPbouiCOM.Application, ByVal aFormUid As String, ByVal strUniqueID As String, ByVal Str As String)
        ''********************************************************************
        Dim oMenuItem As SAPbouiCOM.MenuItem = Nothing
        Dim oMenus As SAPbouiCOM.Menus = Nothing
        Dim oCreationPackage As SAPbouiCOM.MenuCreationParams = Nothing
        Dim aForm As SAPbouiCOM.Form = Nothing

        ''********************************************************************
        aForm = SBO_Application.Forms.Item(aFormUid)
        oCreationPackage = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)
        ''********************************************************************
        Try
            oCreationPackage.Checked = False
            oCreationPackage.Enabled = True
            oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING
            oCreationPackage.UniqueID = strUniqueID.Trim
            oCreationPackage.String = Str.Trim
            aForm.Menu.AddEx(oCreationPackage)
        Catch ex As Exception

        Finally
            If oMenuItem IsNot Nothing Then
                oMenuItem = Nothing
            End If
            If oMenus IsNot Nothing Then
                oMenus = Nothing
            End If
            If oCreationPackage IsNot Nothing Then
                oCreationPackage = Nothing
            End If
            If aForm IsNot Nothing Then
                aForm = Nothing
            End If
        End Try
     


    End Sub

13 March 2018

Add Linked Button through SAP Business One SDK- VB.NET

Add Linked Button through SAP Business One SDK- VB.NET

Introduction:

SAP Business One is a powerful enterprise resource planning (ERP) solution that allows businesses to streamline their operations. One of the key strengths of SAP Business One is its extensibility, which enables developers to enhance the user interface (UI) and functionality according to specific business needs.In this blog post, we will focus on a common customization - adding a linked button to a form using the SAP Business One SDK in VB.NET. Linked buttons are a convenient way to integrate custom functionality into the SAP Business One UI, providing users with quick access to specific actions.

Public Sub AddLinkedButton(ByVal objForm As SAPbouiCOM.Form, ByVal ItemUID As String, ByVal SourceID As String, ByVal iLeft As Integer, ByVal iWidth As Integer, ByVal iHeight As Integer, ByVal LinkTo As String, ByVal strLinkedObjectType As String, ByVal strLinkedObject As String)
        Dim oItem As SAPbouiCOM.Item = Nothing
        Try
            If objForm IsNot Nothing Then
                oItem = objForm.Items.Add(ItemUID, SAPbouiCOM.BoFormItemTypes.it_LINKED_BUTTON)
                oItem.Top = objForm.Items.Item(SourceID).Top
                oItem.Left = iLeft + (objForm.Items.Item(SourceID).Left + objForm.Items.Item(SourceID).Width)
                oItem.Width = iWidth
                oItem.Height = iHeight
                oItem.LinkTo = LinkTo
                Dim btn As SAPbouiCOM.LinkedButton = objForm.Items.Item(ItemUID).Specific '' To Assign New Button
                btn.LinkedObjectType = strLinkedObjectType
                btn.LinkedObject = strLinkedObject
            End If
        Catch ex As Exception
        Finally
            If objForm IsNot Nothing Then
                objForm = Nothing
            End If
            If oItem IsNot Nothing Then
                oItem = Nothing
            End If
        End Try
    End Sub

To summarize, adding a linked button in SAP Business One SDK in VB.NET requires specific steps for successful implementation. This enhances functionality and customization in the platform.

12 March 2018

Fill Record into Grid through SDK

Dear All,
   Today , We will see, How to Fill Record into Grid through SDK.



 Public Sub FillRecordIntoGrid(ByVal aform As SAPbouiCOM.Form, ByVal oGridUid As Object, ByVal strQuery As String)
        Dim dtTemp As SAPbouiCOM.DataTable = Nothing
        Dim oGrid As SAPbouiCOM.Grid = Nothing
        Try
            aform.Freeze(True)
            oGrid = aform.Items.Item(oGridUid).Specific
            dtTemp = oGrid.DataTable
            dtTemp.ExecuteQuery(strQuery)
            oGrid.DataTable = dtTemp
        Catch ex As Exception
        Finally
            If dtTemp IsNot Nothing Then
                dtTemp = Nothing
            End If
            aform.Freeze(False)
        End Try
    End Sub

Add user Permission to Form through SDK

Dear All,
   Today , We will see, How to Add user Permission to Form through SDK


 Public Function AddUserPermissionTree(ByVal strPermissionId As String, ByVal strName As String, ByVal strMode As SAPbobsCOM.BoUPTOptions, ByVal intLevel As Integer, ByVal strFatherId As String) As Boolean
        '**********************************************
        '' DECLARE LOCAL VARIABLE(S)
        '**********************************************
        Dim li_RetVal As Integer = 0
        Dim pUserPer As SAPbobsCOM.UserPermissionTree = Nothing
        Dim blnReturn As Boolean = False
        '**********************************************
        oApp = New ClsSAPConn
        pUserPer = oApp.SAPCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserPermissionTree)
        '**********************************************
        Try
            If pUserPer.GetByKey(strPermissionId) = False Then
                pUserPer.PermissionID = strPermissionId
                pUserPer.Name = strName

                pUserPer.Options = strMode
                li_RetVal = pUserPer.Add()
                If li_RetVal <> 0 Then
                    blnReturn = False
                Else
                    blnReturn = True
                End If
            Else
                pUserPer.Name = strName
                pUserPer.Options = strMode
                li_RetVal = pUserPer.Update()
                If li_RetVal <> 0 Then
                    blnReturn = False
                Else
                    blnReturn = True
                End If
            End If
        Catch ex As Exception
            blnReturn = False
        Finally
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pUserPer)
            If oApp IsNot Nothing Then
                oApp = Nothing
            End If
        End Try
        Return blnReturn
    End Function

11 March 2018

Add UserDataSource To Form through SDK

Dear All,
   Today , We will see, How to Add UserDataSource To Form through SDK.


 Public Sub AddUserDataSourceToForm(ByVal aForm As SAPbouiCOM.Form, ByVal oUserDataSorce As String, ByVal strDateType As SAPbouiCOM.BoDataType, ByVal length As Integer)

        Try
            aForm.DataSources.UserDataSources.Add(oUserDataSorce, strDateType, length)
        Catch ex As Exception
        Finally
            If aForm IsNot Nothing Then
                aForm = Nothing
            End If
        End Try


    End Sub

A Step-by-Step Tutorial on Getting Item Alias Names through SDK

            To retrieve an Item Alias Name using the SAP Business One SDK in VB.NET, you can use the following code snippet



 Public Function GetItemAliasName(ByVal SBO_Application As SAPbouiCOM.Application, ByVal oFormType As String, ByVal strItemUid As String, Optional ByVal strColUid As String = "") As String
        Dim resource As SAPbouiCOM.ResourceData = Nothing
        Dim oFormInfo As SAPbouiCOM.FormInfo = Nothing
        Dim oItemInfo As SAPbouiCOM.ItemInfo = Nothing
        Dim strFormType As String = String.Empty
        resource = SBO_Application.ResourceData
        oFormInfo = resource.GetFormInfo(oFormType)
        Try
            oItemInfo = oFormInfo.GetItemInfo(strItemUid, strColUid)
            strFormType = oItemInfo.Alias.Trim
        Catch ex As Exception
            strFormType = String.Empty
        Finally
            If resource IsNot Nothing Then
                resource = Nothing
            End If
            If oFormInfo IsNot Nothing Then
                oFormInfo = Nothing
            End If
            If oItemInfo IsNot Nothing Then
                oItemInfo = Nothing
            End If
        End Try
        Return strFormType.Trim

    End Function

How to Get Form Info through the SAP B1 SDK

Dear All,
   Today , We will see, How to Get Form Info through SDK



    Public Function GetFormType(ByVal SBO_Application As SAPbouiCOM.Application, ByVal oFormType As String) As String
        Dim resource As SAPbouiCOM.ResourceData = Nothing
        Dim oFormInfo As SAPbouiCOM.FormInfo = Nothing
        Dim strFormType As String = String.Empty
        resource = SBO_Application.ResourceData
        oFormInfo = resource.GetFormInfo(oFormType)
        Try
            strFormType = oFormInfo.Type
        Catch ex As Exception
            strFormType = String.Empty
        Finally
            If resource IsNot Nothing Then
                resource = Nothing
            End If
            If oFormInfo IsNot Nothing Then
                oFormInfo = Nothing
            End If
        End Try
        Return strFormType.Trim

    End Function

10 March 2018

Add Form through SDK

Dear All,
   Today , We will see, How to Add Form through SDK



  Public Sub AddForm(ByVal SBO_Application As SAPbouiCOM.Application, ByVal aForm As String, ByVal strUniqueID As String, ByVal strFormType As String, ByVal FormXml As String)
        Dim oForm As SAPbouiCOM.Form = Nothing
        Dim creationPackage As SAPbouiCOM.FormCreationParams = Nothing
        Try
            creationPackage = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)
            creationPackage.UniqueID = strUniqueID
            creationPackage.FormType = strFormType
            creationPackage.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Fixed
            creationPackage.XmlData = FormXml
            oForm = SBO_Application.Forms.AddEx(creationPackage)

        Catch ex As Exception
        Finally
            If oForm IsNot Nothing Then
                oForm = Nothing
            End If
            If creationPackage IsNot Nothing Then
                creationPackage = Nothing
            End If

        End Try
        
    End Sub

Check Item Exists on Form through SDK

Dear All,
   Today , We will see, How to Check Item Exists on Form through SDK


Public Function IsCheckItemExists(ByVal aForm As SAPbouiCOM.Form, ByVal aItemUId As String) As Boolean
        Dim oItem As SAPbouiCOM.Item = Nothing
        Dim blnResult As Boolean = False
        Try
            oItem = aForm.Items.Item(aItemUId)
            blnResult = True

        Catch ex As Exception
            blnResult = False
        Finally
            If oItem IsNot Nothing Then
                oItem = Nothing
            End If
        End Try

        Return blnResult
    End Function

Check Form Exists through SDK

Dear All,
   Today , We will see, How to Check Form Exists through SDK



   Public Function IsCheckFormExists(ByVal SBO_App As SAPbouiCOM.Application, ByVal aForm As String) As Boolean
        Dim oForm As SAPbouiCOM.Form = Nothing
        Dim blnResult As Boolean = False
        Try
            oForm = SBO_App.Forms.Item(aForm)

            blnResult = True

        Catch ex As Exception
            blnResult = False
        Finally
            If oForm IsNot Nothing Then
                oForm = Nothing
            End If
        End Try

        Return blnResult
    End Function

08 March 2018

Split String Price in Matrix SAP B1

Dear All,
   Today , We will see, How to Split string Price in Matrix SAP B1



    Public Function SAPPriceSpliter(ByVal aForm As SAPbouiCOM.Form, ByVal aMatrixUid As Object, ByVal oColId As Object, ByVal oRowId As Object) As Double
        '**********************************************
        ' Declare Local Variable
        '**********************************************
        Dim oMatrix As SAPbouiCOM.Matrix = Nothing
        Dim dblPurPrice As Double = 0
        '**********************************************
        oMatrix = aForm.Items.Item(aMatrixUid).Specific
        Try
            Dim result As String = Regex.Replace(oMatrix.Columns.Item(oColId).Cells.Item(oRowId).Specific.Value, "[a-zA-Z\s]+", String.Empty)
            dblPurPrice = Convert.ToDouble(result)
        Catch ex As Exception
            dblPurPrice = 0
        Finally
            If oMatrix IsNot Nothing Then
                oMatrix = Nothing
            End If
        End Try
        Return dblPurPrice

    End Function

07 March 2018

SAP B1: How to Populate Combo Box Values Using SDK

Introduction:
In SAP Business One, combo boxes offer a convenient way to select predefined values within the user interface. Today, we'll delve into the SAP Business One Software Development Kit (SDK) to understand how to populate and fill a combo box dynamically.

Requirements:
SAP Business One SDK installed and configured.
Familiarity with C# or VB.NET programming languages.
Step-by-Step Guide:
1. Connect to SAP B1 Company Database
Ensure that your SDK environment is set up and correctly connected to the SAP B1 company database.

2. Access the Combo Box Object
Retrieve the combo box object you want to populate with values. Identify the specific combo box control by its unique ID or name.

3. Define Values to Populate
Prepare the values you wish to fill into the combo box. These can be retrieved from a database, predefined list, or generated dynamically.

4. Populate Combo Box with Values


 Public Sub FillComboBoxValue(ByVal oApp As Object, ByVal aForm As SAPbouiCOM.Form, ByVal aComUId As Object, ByVal strQuery As String, ByVal blnDefNew As Boolean)
        '********************************************
        '' DECLARE LOCAL VARIABLES'
        '********************************************
        Dim aCombo As SAPbouiCOM.ComboBox = Nothing
        Dim oRS As SAPbobsCOM.Recordset = Nothing
        '********************************************
        oApp = New ClsSAPConn
        '********************************************
        oRS = oApp.SAPCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
        aCombo = aForm.Items.Item(aComUId).Specific
        '******************************************
        Try

            oRS.DoQuery(strQuery)
            '' To Avoid Valid Value Issue
            If aCombo.ValidValues.Count > 0 Then
                For i As Integer = 1 To aCombo.ValidValues.Count
                    aCombo.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index)
                Next
            End If
            If oRS.RecordCount > 0 Then
                While Not oRS.EoF
                    aCombo.ValidValues.Add(oRS.Fields.Item(0).Value, oRS.Fields.Item(1).Value)
                    oRS.MoveNext()
                End While
            End If
            Select Case blnDefNew
                Case True
                    aCombo.ValidValues.Add("-9", "DEFINE NEW")
                Case False
                    aCombo.ValidValues.Add("", "")
            End Select
            aCombo.Item.DisplayDesc = True


        Catch ex As Exception
        Finally
            If aCombo IsNot Nothing Then
                aCombo = Nothing
            End If
            If oApp IsNot Nothing Then
                oApp = Nothing
            End If
        End Try
    End Sub

Set Current Date Edit Text through SDK

Dear All,
   Today , We will see, How to Set Current Date Edit Text through SDK


    Public Sub SetCurrentDate(ByVal aForm As SAPbouiCOM.Form, ByVal strEditText As String)
        Dim oEditText As SAPbouiCOM.EditText = Nothing
        oEditText = aForm.Items.Item(strEditText).Specific
        Try
            oEditText.Value = DateTime.Now.ToString("yyyyMMdd")
        Catch ex As Exception

        Finally
            If oEditText IsNot Nothing Then
                oEditText = Nothing
            End If
        End Try
    End Sub

Get Combo Box Selected Value SAP SDK

Dear All,
   Today , We will see, How to set Get Combo Box Selected Value through SDK.


Public Function GetComboBoxSelectedValue(ByVal oForm As SAPbouiCOM.Form, ByVal oComUID As String) As Object
        '*****************************************
        'DECLARE LOCAL VARIABLE(S)
        '*****************************************
        Dim oComboBox As SAPbouiCOM.ComboBox = Nothing
        '*****************************************
        oComboBox = oForm.Items.Item(oComUID).Specific
        Try
            Return oComboBox.Value.Trim()
        Catch ex As Exception
            Return Nothing
        Finally
          
        End Try
    End Function

Display Auto Select Value in ComboBox through SDK

Dear All,
   Today , We will see, How to Display Auto Select Value in ComboBox through SDK.


    Public Sub DisplayAutoSelValue(ByVal oApp As Object, ByVal aForm As SAPbouiCOM.Form, ByVal aComUId As Object, ByVal intIndex As Integer)

        '********************************************
        '' DECLARE LOCAL VARIABLES'
        '********************************************
        Dim aCombo As SAPbouiCOM.ComboBox = Nothing
        Dim oRS As SAPbobsCOM.Recordset = Nothing
        '********************************************
        oApp = New ClsSAPConn
        '********************************************
        oRS = oApp.SAPCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
        aCombo = aForm.Items.Item(aComUId).Specific
        '********************************************
        Try
            aCombo.Select(intIndex, SAPbouiCOM.BoSearchKey.psk_Index)
        Catch ex As Exception
        Finally
            If aCombo IsNot Nothing Then
                aCombo = Nothing
            End If
            If oApp IsNot Nothing Then
                oApp = Nothing
            End If
        End Try
    End Sub

06 March 2018

Add button through SDK

Dear All,
   Today , We will see, How to Add button through SDK



Friend Sub AddButton(ByVal objForm As SAPbouiCOM.Form, ByVal SourceID As String, ByVal ItemUID As String, ByVal iLeft As Integer, ByVal iWidth As Integer, ByVal LinkTo As String, ByVal Caption As String, ByVal iHeight As Integer)
        Try
            Dim oItem As SAPbouiCOM.Item
            If objForm IsNot Nothing Then
                oItem = objForm.Items.Add(ItemUID, SAPbouiCOM.BoFormItemTypes.it_BUTTON)
                oItem.Top = objForm.Items.Item(SourceID).Top
                oItem.Left = iLeft + (objForm.Items.Item(SourceID).Left + objForm.Items.Item(SourceID).Width)
                oItem.Width = iWidth
                oItem.Height = iHeight
                oItem.LinkTo = LinkTo
                Dim btn As SAPbouiCOM.Button = objForm.Items.Item(ItemUID).Specific '' To Assign New Button
                btn.Caption = Caption
            End If
        Catch ex As Exception

        Finally
          
        End Try
    End Sub

Cursor focus on Grid Row

Dear All,
   Today , We will see, How to set Cursor focus on Grid Row through SDK.



C#.Net
_Grid.Columns.Item("Colunique").Click(0, false, 0);

VB.net
_Grid.Columns.Item("Colunique").Click(0, false, 0)

Get Matrix Combo Box Selected Value through SDK

Dear All,
   Today , We will see, How to Get Matrix Combo Box Selected Value through SDK.


Public Function GetComboBoxSelectedValue(ByVal oMatrix As SAPbouiCOM.Matrix, ByVal intRowIndex As Integer, ByVal intColIndex As Integer) As Integer
        Dim oComBo As SAPbouiCOM.ComboBox = oMatrix.Columns.Item(intColIndex).Cells.Item(intRowIndex).Specific
        Return oComBo.Value.Trim()
    End Function

05 March 2018

Display Define New and Display last value from UDT in SAP B1

Dear All,
   Today , We will see, How to Display Define New and Display last value from UDT through SDK.


Private Sub ComboBox0_ComboSelectAfter(ByVal sboObject As Object, ByVal pVal As SAPbouiCOM.SBOItemEventArg) Handles ComboBox0.ComboSelectAfter
            Try
                If Me.ComboBox0.Selected.Value = "-9" Then
                    SBO_Application.ActivateMenuItem("51202")
                Else
                    Me.ComboBox0.ExpandType = SAPbouiCOM.BoExpandType.et_ValueDescription
                End If
            Catch ex As Exception

            End Try
        End Sub
 Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent

            If pVal.FormTypeEx = "SetColorComboBox.Form1" Then
                Select Case pVal.EventType
                    Case SAPbouiCOM.BoEventTypes.et_FORM_ACTIVATE
                        If pVal.ActionSuccess And pVal.BeforeAction = False Then
                            objForm = SBO_Application.Forms.Item(pVal.FormUID)
                            If objForm IsNot Nothing Then
                                blnForm = False
                                If blnForm = False Then
                                    ComboBoxLoadValues(Me.ComboBox0, "SELECT Code,Name FROM ""@TESTDEFINENEW""  Order by Code")
                                    Me.ComboBox0.Item.DisplayDesc = True
                                End If
                            End If

                        End If
                End Select
            End If
        End Sub

        Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.MenuEvent
            If pVal.BeforeAction And pVal.MenuUID = "51202" Then
                ComboBox0.ValidValues.Remove(ComboBox0.ValidValues.Count - 1, SAPbouiCOM.BoSearchKey.psk_Index)
                ComboBox0.Item.Description = String.Empty
                blnForm = True
            End If

        End Sub




Get UDT Menu Id from SAP B1

Dear All,
   Today , We will see, How to Get UDT Menu Id from SAP B1 through SDK.


'' It is Only No Object Table Type
SELECT convert(nvarchar(6), row_number() over (order by t0.tablename) + 51201),T0.TableName, T0.Descr, T0.TblNum+ 51201 as [Menu ID] FROM OUTB T0 WHERE T0.ObjectType = 0 order by t0.tablename