True Modal Forms in SAP Business One

Implementing a modal form in SAP Business One was laborious.
There was no support for a truly modal form until recently.

Version 9.2 PL 2 introduced a new functionality that allows a developer to indicate that a form is modal.

When creating a new form you can use the property Modality of the FormCreationParams class, to mark the form as modal.

Snippet

public Form LoadForm(string fileName, string formType, BoFormModality modal = BoFormModality.fm_None)
{
    string contents = ReadFileContents(fileName);
    string uniqueId = GenerateUniqueId();
 
    var formDefinition = application.Create<FormCreationParams>(BoCreatableObjectType.cot_FormCreationParams);
    formDefinition.XmlData = contents;
    formDefinition.UniqueID = uniqueId;
    formDefinition.FormType = formType;
    formDefinition.Modality = modal;
 
    return application.Forms.AddEx(formDefinition);
}

Once your form is opened it will be modal, meaning that you cannot move to other forms or perform other operations, without first closing the modal form.

This is very useful in some contexts as you might have already imagined.

Note that there are some ‘quirks’ with it. If your modal form has a LinkedButton that navigates to another form, you will see the new form open in the background, but you will not be able to move to it until you close the modal form.

4 comments

  1. Hi ,

    How can i import this method to my application? I have already a normal form. I want to convert it to a modal form. Where can i use this Load function?

    I am newbie in SAP B1.

    Thanks.

    Reply

    1. Hi Hüseyin,

      If you just want to convert your form to a modal form, you only need to set the formDefinition.Modality property.
      You can do this in code or in the form XML.

      Note that the Modality property is only available in 9.2 so you’ll not find it in older versions.

      Reply

  2. Much better if you put the following function in your snippet.

    string contents = ReadFileContents(fileName);
    string uniqueId = GenerateUniqueId();

    Reply

    1. Hi Bryan,

      The main point was to show the new property to turn a form into a modal form.
      However, I’ll do another blog post regarding loading of user forms into Business One.

      Cheers.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *