cancel
Showing results for 
Search instead for 
Did you mean: 

Sales Order Form: Validate Event for Customer Reference No Field

Former Member
0 Kudos

Hi to all.

My objective is to create code/logic to check if a duplicate PO for a given customer has been entered on  the sales order form and prevent it.

The desired action, if a duplicate was found, is to give a message box to the user indicating the problem. When the box is closed, I want to clear the Customer Reference No field on the form and then set focus back to the field for a new entry.

I did this. It all works, except.....

Nothing I do can cause the focus to be set to the Customer Reference No field. It always advances to the next field, which is currency.

Here is my event code.....

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

     Dim oEditCardCode As SAPbouiCOM.EditText

     Dim oEditNumAtCard As SAPbouiCOM.EditText

     'check if sales order form generated this event

     If ((pVal.FormType = 139) And (pVal.EventType <> SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD)) Then

           '// get access to the event sending form

          oOrderForm = SBO_Application.Forms.GetFormByTypeAndCount(pVal.FormType,pVal.FormTypeCount)

           'validation test for duplicate PO number

          If ((pVal.ItemUID = "14") And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_VALIDATE) And (pVal.InnerEvent = False) And (pVal.BeforeAction = False)) Then

               'Get access to the text boxes in order to get the existing values

               oEditCardCode = oOrderForm.Items.Item("4").Specific

               oEditNumAtCard = oOrderForm.Items.Item("14").Specific

               Dim ActiveItem As String = oOrderForm.ActiveItem

               If oEditNumAtCard.Value <> "" Then

                     'Validate entered PO here.

                    'see if any orders exist with the same BP and PO numbers in the order table

                    If ManageSQLServer.ReturnPOCount(Trim(oEditCardCode.Value), Trim(oEditNumAtCard.Value)) Then

                         'one or more was found, so message user

                         SBO_Application.MessageBox("Please check the PO number; the entered PO number already exists for this customer.")

                         'set focus to edit box

                        'oOrderForm.ActiveItem = ActiveItem

                          'Make PO edit box empty

                         oEditNumAtCard.Value = ""

                    End If

               End If

          End If

     End If

End Sub

Can anyone see an obvious error? I personally think the form is overriding my set focus code somehow.

Thanks,

Mark

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Mark,

You should do your edit on BEFOREACTION and when you detect the error, just set bubbleevent = false.

Former Member
0 Kudos

Thanks; that worked!

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi, if you want to check if that Customer reference is already exist. Why don't you use recordset.

Try this one. Catch the press event then put this one.

Dim oRec As SAPbobsCOM.Recordset

Dim oCompany As SAPbobsCOM.Company

Dim oStr As String

Dim NumAtCard As SAPbouiCOM.EditText = oForm.Items.Item("14").Specific 'This is NumAtCard

oRec = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

oStr = "SELECT NumAtCard FROM OPOR WHERE NumAtCard = '"& NumAtCard.Value &"'"

oRec.DoQuery(oStr)

'So basically if the recordset found a record, it is already use by other PO.

If oRec.RecordCount > 0 Then

'Your condition. Example.

NumAtCard.Value = ""

yourForm.Items.Item("YourItem").Click(SAPbouiCOM.BoCellClickType.ct_Double) 'This will focused your NumAtCard

SBO_Application.MessageBox("Please check the PO number; the entered PO number already exists for this customer.")

End If

I think it will answer this your problem.

Regards,

Former Member
0 Kudos

To focus it to edit textbox. You can use this code.

yourForm.Items.Item("YourItem").Click(SAPbouiCOM.BoCellClickType.ct_Double)

Put that code after this :

SBO_Application.MessageBox("Please check the PO number; the entered PO number already exists for this customer.")

Former Member
0 Kudos

This was an interesting reply but fails in the same way......

Former Member
0 Kudos

Hi Mark,

You can do it with transaction notification procedure as well then why doing through SDK ??

Regards

Former Member
0 Kudos

Well, I could use a little direction on how to do that.....can you point me to a resource?