Skip to Content
0

Reflection in SAP B1 SDK

Jan 11, 2017 at 12:00 PM

83

avatar image
Former Member

Hi, ALL

I'm trying to implement a reflection over the BusinessPartners object, but I'm getting the following error: "Object reference not set to an instance of an object.".

Bellow follows the source code:

 BusinessPartners PN = sapCom.Company.GetBusinessObject(BoObjectTypes.oBusinessPartners);

            Type BussinessPartnesType = PN.GetType(); // typeof(BusinessPartners);
            PropertyInfo propertySet = BussinessPartnesType.GetProperty("CardName", BindingFlags.Instance);
            propertySet.SetValue(PN, "BusinessPartners Test", null);
            PN.Add();

What can be done to achieve a similar result?
10 |10000 characters needed characters left characters exceeded

Your code should work also with the following change.

Type BussinessPartnesType = PN.GetType();// typeof(BusinessPartners);

to

Type BussinessPartnesType = typeof(SAPbobsCOM.IBusinessPartners);

Note that you need to get the Interface, not the class it self. (IBusinessPartners, not BusinessPartners)

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
DIEGO LOTHER Jan 11, 2017 at 12:30 PM
0

Hi Andrew,

Try to use the InvokeMember method like below:

BusinessPartners PN = oCompany.GetBusinessObject(BoObjectTypes.oBusinessPartners);


Type BusinessPartnesType = PN.GetType();
BusinessPartnesType.InvokeMember("CardName", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.Public, null, PN, new object[] { "BusinessPartners Test" });
Console.WriteLine(PN.CardName);

Kind Regards,

Diego Lother

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank is working!

0