cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a BP from Vb.net

Former Member
0 Kudos

Hi you all!!. I'm trying to add a BP from Vb.Net. I've followed all steps defined on the SDK. I've added the required fields:

Dim vBP As SAPbobsCOM.BusinessPartners

vBP = Conexion.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners) (Conexion.Company is a class managing the connection to SB1)

vBP.CardName = txt_NuevoIC.text

vBP.CardType = SAPBobsCOM.BoCardTypes.cLid

vBP.CardCode = Generar_CardCode()

Dim ernum as Interger = vBP.Add()

Dim erText as Text =""

if ernum<>0 then     -------------->Error

Conexion.Company.GetLastError(ernum, erText)

end If

When I perform the ADD instruction I get error -4002: "To generate this document, first define the numbering series in the Administration module"

I've already defined the series for this documents (clients and providers). There're not authorization problems cause mine is a super user and has been  granted access to everywhere

First thought was to define manually the series number, using:

vBP.Series = 46  (The number of my series)

But the only thing I receive is a giant error of MEMORY!!...and says it couldn't find the source code ¿¿??

I'll really appreciate the help

Thanks in advance!!!

Greetings.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Jose,

   This code works to me. Try

try

{

          BusinessPartners lBusinessPartner = Connection.B1Connection.GetBusinessObject(BoObjectTypes.oBusinessPartners);

          lBusinessPartner.CardCode = "CR1";

          lBusinessPartner.CardName = "Name";

          lBusinessPartner.CardType = BoCardTypes.cSuplier;

          lBusinessPartner.Series   = 1;

           foreach (var lInfoEndereco in oDadosParceiro.InfoEnderecos)

          {

                    var lEndereco  = lBusinessPartner.Addresses;

                    lEndereco.AddressName = Convert.ToString(lBusinessPartner.Addresses.Count) + 1;

                    lEndereco.Street = "Logradouro";

                    lEndereco.StreetNo = "Numero";

                    lEndereco.Block = "Bairro";

                    lEndereco.County = "Municipio";

                    lEndereco.State = "UF";

                    lEndereco.ZipCode = "CEP";

                    lEndereco.Country  = "Brasil";

                    lEndereco.BuildingFloorRoom = "Nenhum complemento";

                    lEndereco.Add();

          }

          if (!Connection.B1Connection.InTransaction)

               Connection.B1Connection.StartTransaction();

          lResultAdd = (lBusinessPartner.Add() == 0);

          if (!lResultAdd)

                    throw new Exception(Connection.B1Connection.GetLastErrorCode() + ":" + Connection.B1Connection.GetLastErrorDescription());

}

finally

{

          if (Connection.B1Connection.InTransaction)

              Connection.B1Connection.EndTransaction(lResultAdd ? BoWfTransOpt.wf_Commit : BoWfTransOpt.wf_RollBack);

}

Regards,

Paulo Henrique

Former Member
0 Kudos

Hi Paulo.

I've tried your solution several times, and it's not working. In fact, this thing is so weird that I placed the code line "vBP.Series = 46" (or vBP.Series = 1 like you comment) on a Try Catch EndTry and the error is NOT catched by the TRY. It stop the entire processing and shows the message I mentioned before (reading o writting on protected memory) ¿¿¿??

I've tried this, and it works:

1.- Follow this path:

Administration->System Initialization->Document Numbering->BusinessPartner-Customer (Double Click)

 

2.- Unckeck the Field "Lock" in MANUAL.

This way, the code works perfectly from vb and adds the BP without any problem. The thing is my client has told us (the developer team) not to use the MANUAL setting, meaning that the cardcode must be created automatically. 

So, we thought that MAYBE (and I'm not sure of this) keep this code just like this and THEN, execute a query that update the new record on the OCRD table in order to update Series and Number fields to adjust to the parameters defined on the NNM1 table.

What do you think?

Please, try to check the 2 steps I mentioned before and verify if your Lock field is check. If it's check try to uncheck it and run again your code. If this works, it means that there's something wrong with my libraries or something else.

Greetings.

Former Member
0 Kudos

Hi Jose,

Registered a new numbering for business partner. Done this, canceled the old numbering, leaving only one for selection and I used the same programming code, only modifying of Series = 1 for Series = 47 (number of my series on table NNM1).


Done the above procedure, performed the test and worked properly.


How to perform the update, just remember that it is not allowed to perform update via SQL. If you perform any update directly in the database, you will lose the warranty and support from SAP. This is a rule of them. All commands that involve data should be performed via DI API or UI API.

Try:

  1. Close all SAP applications (SBO, SAP Business One UI API) e all process related to SAP
  2. Clean the %temp%\SM_OBS_DLL
  3. In 'Local Settings' folder (\Application Data\SAP\SAP Business One) clean all log files

Regards,

Paulo Henrique

Former Member
0 Kudos

Hi Paulo.

I'm Sorry, but I've tried everything that you and everyone else suggested me, but nothing seems to work.

The only way I get my BP created on B1 is unckecking the field "LOCK" in the path I posted before.

I've tried to create a new numbering for the BP as you suggested and changed my code using: BP.Series = 47. But it keeps popping the same error on reading protected memory ¿¿¿???. To add more spice to this mistery, I placed this single line between a Try-EndTry block and it doesn't work. The catch does NOT "catch" the mistake

As I said, the only way I can make it work is unckecking the LOCK field where you define the numbering sequence for the BP. But, I can't unckeck that field because my client had requested me not to do it.

I don't know what to do. Any thoughts???

Regards.

Former Member
0 Kudos

Hi Jose,

I ran the tests again, and ' Lock ' only serves to demonstrate if that value is visible or not. Soon, I realized that you're trying to register a business partner with a numbering of documents that this disabled. The DI API will not allow.


In my test, registered a new sequence, with 48 code and put the ' Lock '. And I tried to register a business partner with this numbering. The DI API I returned the following error:


To generate this document, first define the numbering series in the Administration module.


AfterI removedthe option to'Lock 'andworked properly. Check withyour client, butI think he'swrongon thefunctionality of theoption 'Lock '. Followtest code.

Just to remind, the DI API makes the same validations that the SAP. Soon, through the interface you can't add, will not get via DI API also.

try

{

          BusinessPartners lBusinessPartner = SBO_DICompany.GetBusinessObject(BoObjectTypes.oBusinessPartners);

 

          //lBusinessPartner.CardCode = aParceiro.Code;

          lBusinessPartner.CardName = "Sample name";

          lBusinessPartner.CardType = BoCardTypes.cCustomer;

          lBusinessPartner.Phone1   = "+55489887488";

          lBusinessPartner.Series   = 48;

 

          #region Adress

 

          var lEndereco               = lBusinessPartner.Addresses;

          lEndereco.AddressType       = BoAddressType.bo_BillTo;

          lEndereco.AddressName       = "Sample adress";

          lEndereco.Street            = "Sample Street";

          lEndereco.StreetNo          = "421";

          lEndereco.Block             = "Sample Block";

          lEndereco.County            = "Sample County";

          lEndereco.ZipCode           = "Sample ZipCode";

 

          lEndereco.Add();

           #endregion

           if (!SBO_DICompany.InTransaction)

                    SBO_DICompany.StartTransaction();

 

          var lResultAdd = (lBusinessPartner.Add() == 0);

          if (!lResultAdd)

                    throw new Exception(SBO_DICompany.GetLastErrorCode() + ":" + SBO_DICompany.GetLastErrorDescription());

}

catch (Exception Ex)

{

          Console.WriteLine(Ex.ToString());

}

finally

{

          if (SBO_DICompany.InTransaction)

                    SBO_DICompany.EndTransaction(BoWfTransOpt.wf_Commit);

}

Regards,

Paulo Henrique

Former Member
0 Kudos

Hi Paulo.

Actually, and I don't now why it works now, I did "again" what you post several days ago about deleting all temps and log files. Rerun and BANG!!...works smooth!!!

Thanks for your help!!!

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Beni.

Thanks for the quick answer.

I can't use anyhow the Series Propierty. Every time I try to set a value on it, keeps throwing an error on Trying to read or write on protected memory (i'm translating it from spanish).

Any thoughts?

Greetings.

Former Member
0 Kudos

Try set the Series to 1 (manual series for Customers).

Beni.