cancel
Showing results for 
Search instead for 
Did you mean: 

Modal Form Event handling?

former_member231954
Participant
0 Kudos

I am using C# SAP UI+DI API 9.2 for SAP Business One 9.2 and trying to use the Modal Form pattern (shown in the examples, UI: 12.ModalForm). I have a form, that opens multiple modal forms, these would ask for some input and after the OK event, something would happen on the main form. I can make a model form, just like the sample, but my question is: How can I handle the OK or Close event? The modal form is displayed as a new form, the user can interact with the main form while a model one is open and I don't know If the modal is closed already.

Let's say my main form has a list of items from OITM. The user opens a modal form by clicking on a button on the main form. Selects an action, that should do something with the items (updating fields for example), presses OK on the modal form, which closes it. Now I should reload the list on the main form, to load the updated items. How would I do it? Can I catch the modal form OK event somehow and trigger the reload?

Accepted Solutions (0)

Answers (2)

Answers (2)

pedro_magueija
Active Contributor
0 Kudos

Hi Szabolcs,

Just a reminder, SAP implemented a proper Modal property for forms. You can use the FormCreationParams.Modality to mark a form as modal.


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

former_member231954
Participant
0 Kudos

I create my forms in B1Studio an export them as XML, which I load when I am opening a form. Do I just put a Modality="1" attribute to the form element then?

pedro_magueija
Active Contributor
0 Kudos

Hi Szabolcs,

You can do something like this:

public Form LoadForm(string fileName, BoFormModality modal = BoFormModality.fm_None)

{

    string contents = ReadFileContents(fileName);

    string uniqueId = Guid.NewGuid().ToString("N");

    var formDefinition =

        (FormCreationParams) application.CreateObject(BoCreatableObjectType.cot_FormCreationParams);

    formDefinition.UniqueID = uniqueId;

    formDefinition.XmlData = contents;

    formDefinition.Modality = modal;

    return application.Forms.AddEx(formDefinition);

}

Still allows you to load your XML, but gives you the flexibility to set some params.


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

former_member231954
Participant
0 Kudos

I tried it, but I get an Exception when the form is being loaded:

Could not load type 'SAPbouiCOM.BoFormModality' from assembly 'SAPBusinessOneSDK, Version=1.0.0.1, Culture=neutral, PublicKeyToken=c7c3cb60e45d119f'.

I have 9.2 SDK installed and used the DLL from there.

Edit: If I use the DLL from C:\Program Files (x86)\SAP\SAP Business One SDK\Lib\SAPBusinessOneSDK.dll , I get the Exception above, but If I use the two separate assemblies (SAPbobsCOM and SAPbouiCOM) from the VS Assemblies library, it works. :S

Now I went back to use the two separate ones. :S

pedro_magueija
Active Contributor
0 Kudos

Hi Szabolcs,

Hmm... weird. What's your patch level?


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

former_member231954
Participant
0 Kudos

SBO 9.0 (9.20.130) PL: 03 (32-bit)

If PL means Patch Level, otherwise:

We have a Hungarian version of SAP, I cannot find the patch level or the Kernel version as suggested: how to check patch level in SAP 6.0 ? | SCN

pedro_magueija
Active Contributor
0 Kudos

Hi Szabolcs,

Yep, PL is the patch level. Actually your version is greater than mine (I'm on PL02), so it should work with the SAPBusinessOneSDK.dll.

How did you add it to your project references? Did you use the Add Reference -> Assemblies in Visual Studio (recommended)? Or did you browse to the SDK path and added that?


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

pedro_magueija
Active Contributor
0 Kudos

Hi Szabolcs,

My recommendation would be to fire an event from your "child" form, that your "parent" form will catch and process.

Pseudo example:


class ParentForm {

public void OpenChild()

{

  var childForm = new ChildForm();

  childForm.OnInterestingEvent += ProcessInterestingEvent;

  childForm.Open();

{

private void ProcessInterestingEvent(object sender, EventArg args)

{

... update the items

}

}

class ChildForm {

public event EventHandler OnInterestingEvent = delegate {};

private void OnOKButtonPressed(ItemEvent e)

{

  ...

  OnInterestingEvent(this, new EventArgs());

}

}


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.