Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

RE:Formatted Search - Programmatically

Hi All,

How to add Formatted search to a particular EditText through the program.

My requirement is :

I have 3 userdefined field U_CardCode,U_CardName and U_ContactPerson.I want to add a FS to U_CardCode.If i select a BP from the list i should load the corresponding contactperson and BPName in the U_CardName and U_ContactPerson field.

How should i achieve this.

Thanx in advance

Mohana

Former Member
Former Member replied

Hi Mohana,

As requested:

    Public Function CreateQuery(ByRef oCompany As SAPbobsCOM.Company, ByRef oApplication As SAPbouiCOM.Application, _
            ByRef QueryName As String, ByRef TheQuery As String) As Integer
        CreateQuery = -1
        Dim oRS As SAPbobsCOM.Recordset = oCompany.GetBusinessObject(BoObjectTypes.BoRecordset)
        Dim oQuery As SAPbobsCOM.UserQueries = oCompany.GetBusinessObject(BoObjectTypes.oUserQueries)

        Try
            oRS.DoQuery("SELECT TOP 1 INTRNALKEY FROM OUQR WHERE QCATEGORY=" & GetSysCatID(oCompany, oApplication) & _
                " AND QNAME='" & TranslateStr(oApplication, QueryName) & "'")
            If oRS.RecordCount > 0 Then
                CreateQuery = oRS.Fields.Item(0).Value
            Else
                oQuery.QueryCategory = GetSysCatID(oCompany, oApplication)
                oQuery.QueryDescription = TranslateStr(oApplication, QueryName)
                oQuery.Query = TranslateStr(oApplication, TheQuery)
                If oQuery.Add <> 0 Then
                    oApplication.MessageBox(TranslateStr(oApplication, CreateQueryError) & TranslateStr(oApplication, QueryName) & _
                    vbCrLf & TranslateStr(oApplication, Error_) & oCompany.GetLastErrorCode.ToString & ", " & oCompany.GetLastErrorDescription)
                    Exit Function
                End If
                CreateQuery = CInt(Mid$(oCompany.GetNewObjectKey, 1, InStr(1, oCompany.GetNewObjectKey, vbTab) - 1))
            End If
        Catch ex As Exception
            oApplication.MessageBox("CreateQuery(): " & QueryName & vbCrLf & _
            TranslateStr(oApplication, Error_) & oCompany.GetLastErrorCode.ToString & ", " & ex.Message)
        Finally
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oRS)
            oRS = Nothing
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oQuery)
            oQuery = Nothing
            GC.Collect()
        End Try
    End Function

I also provide another function that returns the ID of a Query category with the same description as the Add-on's name.

    Public Function GetSysCatID(ByRef oCompany As SAPbobsCOM.Company, ByRef oApplication As SAPbouiCOM.Application) As Integer
        GetSysCatID = -3
        Dim oRS As SAPbobsCOM.Recordset = oCompany.GetBusinessObject(BoObjectTypes.BoRecordset)

        Try
            oRS.DoQuery("SELECT TOP 1 CATEGORYID FROM OQCN WHERE CATNAME='" & TranslateStr(oApplication, AddOnName) & "'")
            If oRS.RecordCount > 0 Then GetSysCatID = oRS.Fields.Item(0).Value
        Catch ex As Exception
            oApplication.MessageBox("GetQrtCatID(): " & AddOnName & vbCrLf & _
            TranslateStr(oApplication, Error_) & oCompany.GetLastErrorCode.ToString & ", " & ex.Message)
        Finally
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oRS)
            oRS = Nothing
            GC.Collect()
        End Try
    End Function

Regards,

VĂ­tor Vieira

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question