on 07-08-2015 3:02 PM
Greetings all, I'm writing an addon for SAP B1 9.1 and I'm quite stuck as I don't seem to be able to get FormEvents to work. I need to do something every time the Activity form (FormType 651) is opened, and this code currently does nothing at all neither when I open Activity nor when I try loading records (which should trigger BoEventTypes.et_FORM_DATA_LOAD, but that won't work either). Did I miss something?
using SAPbobsCOM;
using SAPbouiCOM;
using B1WizardBase;
public class Form__651 : B1Form
{
public Form__651()
{
FormType = "651";
}
[B1Listener(BoEventTypes.et_FORM_LOAD, false)]
public virtual void OnAfterFormLoad(BusinessObjectInfo pVal)
{
bool ActionSuccess = pVal.ActionSuccess;
Form form = B1Connections.theAppl.Forms.Item(pVal.FormUID);
Connection.SBO_Appln.MessageBox("Hello");
//form.Items.Item("51").Visible = false;
}
}
The main is like this:
public static void Main()
{
try
{
if (!Connection.Connect()) return;
PROJECTNAME_Db addOnDb = new PROJECTNAME_Db();
addOnDb.Add(Connection.oCompany);
PROJECTNAME_Cockpits addOnCockpit = new PROJECTNAME_Cockpits();
addOnCockpit.Manage(Connection.SBO_Appln, Connection.oCompany);
Connection.SBO_Appln.MessageBox("Hello");
System.Windows.Forms.Application.Run();
}
catch (System.Runtime.InteropServices.COMException com_err)
{
System.Windows.Forms.MessageBox.Show("ERROR - Connection failed: " + com_err.Message);
}
}
By the way, the whole addon loads alright and rightly keeps running until I stop the debugger. Thanks in advance!
Hello Luca,
As I understand you are trying to find a trigger to make your code run.
Could you try writing your code under this block to catch the data load event.
private void Form_DataLoadAfter(ref SAPbouiCOM.BusinessObjectInfo pVal)
{
}
Regards,
Atilla
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your reply, Atilla, but I've pretty much solved the problem using an ItemEvent instead of a FormEvent, and of course including
Connection.SBO_Appln.ItemEvent += new SAPbouiCOM._IApplicationEvents_ItemEventEventHandler(new ItemEvents().application_ItemEvent);
in the main method, which I previously didn't. It all works sweetly now, but I'm still wondering why the FormEvent listener didn't work at all and there isn't even a way to add the listener method to an hypothethic Connection.SBO_Appln.FormEvent which only exists for FormDataEvents which are unsuitable for what I need to do.
Hi Luca,
For this way to use events, event listeners are delegates which have to be registered (and unregistered while disposing the object) to be called by the underlying object.
This has nothing to do with SBO SDK, this is regular DotNet programing (no offense intended) which is why I had not answered (and I'm guessing the same for other people).
Saying this, you can simplify the syntax and remove the two new which are useless.
Regards,
Eric
User | Count |
---|---|
101 | |
12 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.