cancel
Showing results for 
Search instead for 
Did you mean: 

UI - Forbidding manual discount change in sales order footer

Former Member
0 Kudos
80

Hello,

I would like to share with you some of my recent experience with UI API ...

I was trying to forbid the user to modify the discount (both in % or in amount) in a sales order footer.

I first thought that it would be a difficult task to do as those are system fields that appeared on the form. I reported to the UI 2004 help file and start seeking restrictions:

What is mentionned is:

- "You cannot set the item's Editable property to Yes." (Item object)

- "You cannot set this property to True for items of system forms. In addition, if the item is in fucus, you cannot set it to False" (Enabled property for Item object)

Please note that I did not want in anyway to alter the system logic related to the calculation of the discount.

On the form type 139, discount percent is item 24 (databound to field ORDR.DiscPrcnt) and value is item 42. Both are enabled and visible so I thought it was ok (how lucky to be safe from sys forms restrictions )

Thus I tried the following piece of code:

    Public Shared Sub ChangeSysItems(ByRef oForm As Form)
        'Deactivating the field for discount percentage on the footer of the document
        If Module1.oInit.bAllowDiscountChange = False Then
            oForm.Items.Item("24").Enabled = False
            oForm.Items.Item("42").Enabled = False
        ElseIf Module1.oInit.bAllowDiscountChange = True Then
            oForm.Items.Item("24").Enabled = True
            oForm.Items.Item("42").Enabled = True
        End If
    End Sub

But this is not working (of course I tripple check that they were not on focus). I try on another sys field (the field Remarks):

oForm.Items.Item("16").Enabled = False

and this works well.

Funny enough you can hide those fields:

oForm.Items.Item("24").Visible = False
oForm.Items.Item("42").Visible = False

But why cannot you disable them?

Any idea?

PS I am working with SAP Business One 2004 A, patch 23.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Nick, you are right!

Actually, it looks like you can disable items 24 and 42 on a sales order form, but any operation which modifies the discount for the document (in percentage and in amount - to be tested), for instance changing the customer (only when customer discount is different? - to be tested), will enable them again. So we have to anticipate that behaviour in our programs...

Cheers,

Cyril

Former Member
0 Kudos

Hi Cyril,

I tried your code, it works. It will disable those two items. Please refer to my code below. BTW, what I did is to catch combo box selecting event, when you select a combo box value, it will diable the two items.

Private Sub m_oApplication_ItemEvent(ByVal FormUid As String, pVal As SAPbouiCOM.ItemEvent, BubbleEvent As Boolean)
Select Case pVal.EventType
    Case et_COMBO_SELECT
        Dim oForm As SAPbouiCOM.Form
        
        If pVal.FormType = 139 Then
            'Set oForm = m_oApplication.Forms.Item(FormUid)
          Set oForm = m_oApplication.Forms.GetForm("139", 1)
            oForm.Items.Item("24").Enabled = False
            oForm.Items.Item("42").Enabled = False
        End If

End Select
End Sub

Best Regards,

Nick He