Skip to Content
0
Former Member
Jul 19, 2005 at 10:27 AM

UI - Forbidding manual discount change in sales order footer

43 Views

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.