Skip to Content
0
Former Member
Jun 08, 2006 at 03:04 PM

Setting UserField values in document rows

21 Views

Hi all

This is the discription of my problem:

I have SP1 PL4, moreover I created 2 user Fields in the row’s of documents they are named: U_AnzVE, U_AnzPal

By code I try to do the following:

I add a new entry for example a Purchase Order (or any other SAPbobs.Documents). In the row I set the values of the UserFields.

And at this point my problem ocurs:

à Each time I set a Field it automaticly adds a new line and the Field value is not set even!

Here is my Code:

namespace COR_TestFieldUpdate
{
    class TesterStart
    {
        public static void Tester()
        {
            try{
                SAPbobsCOM.Documents purch = (SAPbobsCOM.Documents)SwissAddonFramework.B1Connector.GetB1Connector().Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders);
                purch.CardCode = "100160";
                purch.DocDueDate = DateTime.Now;
                purch.Comments = "Comment";


                for (int i = 0; i < 10; i++)
                {

                    purch.Lines.ItemCode = "IT0940211001.5";
                    purch.Lines.Quantity = i;
                    purch.Lines.ShipDate = DateTime.Now;
                    System.Diagnostics.Debug.WriteLine("cout of lines is:" + purch.Lines.Count);
			 
  //here occures the problem a line is added to the pruch.lines without the Lines.Add command!:
  //And as I said the Value is not set eather... 

                    purch.Lines.UserFields.Fields.Item("U_AnzVE").Value = "100";
                    System.Diagnostics.Debug.WriteLine("cout of lines after setting U_AnzVE is:"+purch.Lines.Count);

			  //And here again:

                    purch.Lines.UserFields.Fields.Item("U_AnzPal").Value = "100";
                    System.Diagnostics.Debug.WriteLine("cout of lines after setting U_AnzPal is:" + purch.Lines.Count);

                    if (i != 10 - 1)
                    {
                        purch.Lines.Add();
                    }

                }

                ErrorHandler(purch.Add());
            }
            catch(Exception e)
            { System.Diagnostics.Debug.WriteLine("Exeption :"+e.Message); }
        }

        private static void ErrorHandler(int lRetCode)
        {
            string sErrMsg = "";
            int lErrCode = 0;
            if (lRetCode != 0)
            {
                SwissAddonFramework.B1Connector.GetB1Connector().Company.GetLastError(out lErrCode, out sErrMsg);
                System.Diagnostics.Debug.WriteLine(lErrCode + " " + sErrMsg);
                throw new Exception(lErrCode + " " + sErrMsg);
            }
        }

    }
}

And this is the output that it is generated:

cout of lines is:1

cout of lines after setting U_AnzVE is:2

cout of lines after setting U_AnzPal is:3

cout of lines is:4

cout of lines after setting U_AnzVE is:5

cout of lines after setting U_AnzPal is:6

cout of lines is:7

cout of lines after setting U_AnzVE is:8

cout of lines after setting U_AnzPal is:9

cout of lines is:10

cout of lines after setting U_AnzVE is:11

cout of lines after setting U_AnzPal is:12

cout of lines is:13

cout of lines after setting U_AnzVE is:14

cout of lines after setting U_AnzPal is:15

cout of lines is:16

cout of lines after setting U_AnzVE is:17

cout of lines after setting U_AnzPal is:18

cout of lines is:19

cout of lines after setting U_AnzVE is:20

cout of lines after setting U_AnzPal is:21

cout of lines is:22

cout of lines after setting U_AnzVE is:23

cout of lines after setting U_AnzPal is:24

cout of lines is:25

cout of lines after setting U_AnzVE is:26

cout of lines after setting U_AnzPal is:27

cout of lines is:28

cout of lines after setting U_AnzVE is:29

cout of lines after setting U_AnzPal is:30

C:Dokumente und EinstellungenSAP_AHLokale EinstellungenTemp

SwissAddonDebug.log

-5002 Item no. is missing [line: 30]

Ofc the item code is missing in the 20 lines I didn’t want to add!!!

Do I do something wrong or is it a API Problem?

regards

Andreas