cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use my validation before save ,when I click the Icon of close form?

Former Member
0 Kudos

As the picture,How can I use my Validation in my behide Code?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi  Bryan,$riniva$ Rachumallu  and Edy

         Thanks your ideas and Support. 

         But that is our Add-on and is customization form.

          if I use the SBO_SP_TransactionNotification, I am worried it will be too much thing in one Stored Procedures.

          I use the sample of CatchingEvents, and use the event of et_FORM_CLOSE,But the order it runs is as the picture.

          I can't use my Validation after user click "Yes" .

          Can I catch the event that after user click "Yes" ?

Remark: To use Validation that just I want to prevent user run it out of our rule.

Former Member
0 Kudos

I used like this. If they Press (Y) it will delete all records on Matrix.

  If SAP_APP.SBO_Application.MessageBox("Are you sure you want to delete this Rate Matrix?", 2, , "Cancel") = 1 Then

                                                Delete_Matrix()

                                            End If

Former Member
0 Kudos

     En,But the confirm MessageBox is not dispear from me,just dispear when I Add a part data in the

form(Add-on) ,and click the icon of close.

     Now,I can't catch the event.

     Now I know the confirm MessageBox's Form ID is 0 and "Y" itemID is 1,But I don't know How to

use source Code to get confirm MessageBox's Form ID to compare "0" and itemID to compare 1.

Remark: pVal.FormTypeEx can get Form ID,But I can't use it to get MessageBox's Form ID.

Former Member
0 Kudos

Hi,

You should catch the before et_FORM_DATA_ADD and before et_FORM_DATA_UPDATE events and do the validation in your code.

Beni.

Former Member
0 Kudos

Please post your code.

Former Member
0 Kudos

I just use 'pVal.FormTypeEx' to get the Form ,But the Form ID is father form's ID,Isn't the Confirm

form's ID.

Former Member
0 Kudos

Hi,

     How to trigger the events of  et_FORM_DATA_ADD and before et_FORM_DATA_UPDATE?

     I have try to Add Data,But I can catch et_FORM_DATA_ADD event.

Regards

Former Member
0 Kudos

Hi,

You catch those events under FormDataEvent event, not under ItemEvent.

Beni.

Former Member
0 Kudos

Hi,

     I catch it as you say,it works. Thank you.

Former Member
0 Kudos

Remark(some of my source code):

SBO_Application.FormDataEvent += new _IApplicationEvents_FormDataEventEventHandler(FormDataEvent);

protected void FormDataEvent(ref BusinessObjectInfo busObj, out bool bubbleEvent)

    {

        bubbleEvent = true;

        if ((busObj.EventType == BoEventTypes.et_FORM_DATA_ADD || busObj.EventType == BoEventTypes.et_FORM_DATA_UPDATE) && busObj.BeforeAction)

        {

            if (busObj.FormTypeEx == "FORMID")

            {

                //if (!Validation())

                //{

                    SBO_Application.MessageBox("Can not Save", 1, "Ok", "", "");

                    bubbleEvent = false;

                //}

            }

        }

    }


Answers (3)

Answers (3)

edy_simon
Active Contributor
0 Kudos

Hi Mingwei,

Catch the event of On Before Form Close. Do your validation on the form and stop the closing event if your validation does not meet.

Regards
Edy

Former Member
0 Kudos

hi.

Try below code..

first i need  a small information..

which form u want to validate ..

system form  or  customization form..

i would like to support  Mr.Bryan

why dont u use  sp..

suppose u r validating  system form..

before clicking they have not started  the addon .

addon  can not validate   it..

if u still need  through the code 

try below sample code..

one more information i need ..

why u need  validation at  from close  i am not understanding..

normally people are  closing the form after they complete the work..

  'before clicking  save button

                    If (pVal.FormTypeEx = "140" And pVal.BeforeAction = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_CLICK) Then

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

                        ''Do your validation

                        '' above scenario  for system form  chagne  pval.formtypex  to your from  uid

                    End If

                    If (pVal.FormUID = "yourCustomizationFormuid" And pVal.BeforeAction = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_CLICK) Then

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

                        ''Do your validation

                    End If

                    'Form close

                    If (pVal.FormUID = "yourCustomizationFormuid" And pVal.BeforeAction = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_CLOSE) Then

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

                        ''Do your validation

                    End If

Former Member
0 Kudos

What information you want to validate? In this example from PO, I will block the transaction the the Project field is NULL or no value.

IF (@object_type = '22' AND @transaction_type IN ('A', 'U'))

  BEGIN

  SELECT TOP 1

  @LineNum = a.LineNum + 1

  FROM POR1 a

  INNER JOIN OPOR b ON a.DocEntry = b.DocEntry

  WHERE (a.Project = '' OR a.Project IS NULL) AND b.DocEntry = @list_of_cols_val_tab_del

  IF NOT @LineNum IS NULL

  BEGIN

  SELECT @error = -22,

  @error_message = 'Please define project at line #. '+ @LineNum +'. '

  END

END

Former Member
0 Kudos


The information I want to validate is Null or no value.

But Can I use my validation in my form's BehideCode?

if I don't want to use the Stored Procedures 'SBO_SP_TransactionNotification',

How can I validate my Custom From in the BehideCode?

Former Member
0 Kudos

Hi,

     If I were you. I would used the SBO_SP_TransactionNotification instead of creating add-on.

If you used add-on.

     1. You will deploy it on all SAP user.

     2. You need to maintain the source code.

     3. Will cost more time.

Don't make things so complicated if it is there's a minimal way to do it. Anyway, here's a sample to block NULL or empty value.

            Dim oNumAtCard As SAPbouiCOM.EditText

            oNumAtCard = frmManualDep.Items.Item("14").Specific

            If oNumAtCard.Value = "" Then

                MsgBox("NULL")

            End If

There's a sample to catch the event here at :

C:\Program Files (x86)\SAP\SAP Business One SDK\Samples\COM UI\VB.NET\02.CatchingEvents

Regards,