cancel
Showing results for 
Search instead for 
Did you mean: 

Disable Button in System Form

Former Member
0 Kudos

Dear SAP experts,

I have a rather interesting problem disabling a button from a system form.

I am trying to disable the 'Copy To' button from marketing documents (ID = "10000329");

I disable it using the following instruction:


oForm.Items.Item("10000329").Enabled = false;

It seems to work and in fact the button is grayed out as expected.

However, when I resize the form, the button becomes enabled by itself, even though I didn't change it. The problem also appears when I set it to Visible = false, and also when I set those two properties at the same time.

Surprisingly enough, other buttons don't show this behavior, for example the 'Add' Button (ID = "1").

Does anyone know why? How can I prevent this to happen?

I also tried to change the position of the button outside the form using negative coordinates (so it won't be visible), but it is fairly difficult to locate it in the original coordinates to make it visible again because after resizing, the system refuses to put it back in its place.

Best regards and thanks in advance.

N

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor
0 Kudos

Hi Nicolas,

In systems forms that is tricky. B1 client will "reset" items status based on it's internal logic (admittedly I have no idea what that is).

One way which is common to achieve the blocking of a button is to simply catch the pressing event and check there if the button can execute its operation. If not, set the bubbleEvent to false and SAP will not process the event.

Also note that when you're status depends only on the mode of the form you can use the AutoManagedAttribute method to manipulate the items status, but this does not seem to be your case.

Good luck.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Hi Pedro,

How strange.  I ran the application again after doing some modifications and now is behaving as it should. (?)

pedro_magueija
Active Contributor
0 Kudos

Hi Nicolas,

Yep, like I said it's tricky. It all depends what those changes were.

There are all sorts of tricky situations such as are you loading from xml vs code, the steps taken by the user, etc...

Unfortunately we don't have a straight answer for this. However, if it's possible, please let us know what changes you made. This will help other people as well, and I can also benefit from knowing what you did (maybe I can use it myself) .

Cheers.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

I was revising the code, and there are two major changes.

  1. I cached the results of the calculations mentioned above for each form type (139, 142), for each form instance and for each record displayed in that form instance. If the current record was processed before, the results of the calculations are taken from that structure in memory. If the record was processed before and is now being edited, I remove that from the cache, forcing the calculation again. I don't think that is the reason why it is working now, but could help.
  2. I initially caught the events for Form Items (SBO_Application_ItemEvent), in where the 'resize' event was processed. It looks like it wasn't enough. This is why I added an extra handler for Form Data Event (SBO_Application_FormDataEvent). That new handler also calls the function to show/hide buttons.

I think that 2) was the one that made the difference.

Hope that helps.

Regards.

pedro_magueija
Active Contributor
0 Kudos

Hi Nicolas,

Thanks for sharing. I also think number 2 might be the solution (combined with the other Resize handler).

Cheers.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Answers (2)

Answers (2)

Former Member
0 Kudos

I think This is not possible.

Former Member
0 Kudos

Hi,

     You can capture the form resize by:

SAPbouiCOM.BoEventTypes.et_FORM_RESIZE

'" Put your

  1. oForm.Items.Item("10000329").Enabled = false

Regards,

Bry

Blog: http://www.sap-tips-tricks.com/

Former Member
0 Kudos

Hi Bryan,

There are a couple of issues with that solution.

The first one is that the visibility of that button depends on certain calculations that may be computationally expensive. Ideally I should avoid to perform those calculations as much as I can.

The second issue is that the visibility of the button is reset after processing the resize event. In other words, the button is still invisible when the logic in that event finishes, but it becomes visible again when the event bubbles up.

Many thanks for your contribution anyway.

Best regards.

Nicolas.