cancel
Showing results for 
Search instead for 
Did you mean: 

Open a form

Former Member
0 Kudos

Hello Discussion Group,

I want to open a new form and I have a problem to get a reference on the new form. First I tried something like this:

        Forms.OpenFormByKey("4", null);
        Form myForm = GetFormFromUID(Application.Forms.ActiveForm.UniqueID);

But sometimes another form is on top an I got the wrong form. In the internet are tips like:

oForm=Forms.GetFormByTypeAndCount("4", 1);


I think the second parameter is the count of the forms of this type and my newly created form is the last one? But how will I get the form-count for this type?



Thanks


Martin

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor
0 Kudos

Hi Martin,

Do you really need the reference right after the OpenForm(...)? An alternative could be to catch the after form load event which contains in the arguments (ItemEvent pVal) the exact id of the opened form. You can then use Form.Item(pVal.FormUid) to get the correct form.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

I'm using the CoreSuite AddIn, I'm accessing the API functions by rules. This would create several rules and I would have to connect them. This is not so easy

I can use GetFormByTypeAndCount("150", Count) in a loop to get access to all open ArticelBaseData Forms. The last Form is the one that I have opened. But how can I get the number of opend forms per formtype?

pedro_magueija
Active Contributor
0 Kudos

Hi Martin,

Well if you already have the form instance (of a certain type) you can call form.TypeCount and that returns an int with the number of open form instances.


Each SAP Business One form has a type, which is a unique ID for the form. For example, the type of the Purchase Order form is 142.

Each form can be open multiple times, and the application keeps a counter for each form type of the number of open instances. To get the number of forms open of the same type, use Form.TypeCount. Form objects pointing to different instances of the same type form have the same value in the TypeCount field.

To access a specific instance of a specific form type, use the Forms.GetForm method.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Thanks for the hint

So the dirty (but save) workaround looks like this in Coresuite API translation:

' Open new CustomerOrder Form in ADD mode:

SwissAddonFramework.UI.Components.Form.OpenFormByKey("17", Nothing)

Dim oForm As SwissAddonFramework.UI.Components.Form = SwissAddonFramework.UI.Components.Form.GetFormFromType("139", 1)


oForm = SwissAddonFramework.UI.Components.Form.GetFormFromType("139", oForm.TypeCount)
oForm.Mode = SwissAddonFramework.UI.Components.ModeComponent.FormModes.ADD

Answers (2)

Answers (2)

Former Member
0 Kudos

hi.

i will agree with mr Edy what u said is correct.

if n number of forms are opened  does not a matter.

u can use

oform = sbo_applicaiton.form.activeform

after than

if oform.uniqueid ="fom1" then

your logic

end if

if oform.uniqueid = "form2' the

yur logic

end if.

edy_simon
Active Contributor
0 Kudos

Hi Martin,

But sometimes another form is on top an I got the wrong form.


If you open up a form and the form is successfully opened, your newly opened form should be the Application.Forms.ActiveForm.

I have never encounter another form is on top of the newly opened form.

Regards

Edy

Former Member
0 Kudos

Me too, but it fails by one of our customers. Instead of the requested form, I get a form named "F_60". Maybe a form with AlwaysOnTop Settings?

Is there no nearly safe way to get a reference on the fresh opend form?

edy_simon
Active Contributor
0 Kudos

Hi Martin,

I have never work with Coresuite API.

But if what you are saying is true, it means only one thing.
The coresuite API opens up the form and shifted the focus to another form.

This looks like a bug that you need to report to coresuite.

Regards

Edy