cancel
Showing results for 
Search instead for 
Did you mean: 

Setting UserField values in document rows

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Sorry no this is not the problem

It all works fine with:


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

the problem is that:


purch.Lines.UserFields.Fields.Item("U_AnzVE").Value = "100";

is adding a line and is not setting the value.

if u think about it in this case:


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

and


if (i != 0)
{
    purch.Lines.Add();
}

have the same effect

even:


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

would have the same effect

most important thing is that purch.Lines.Add() is left out one time in the for-loop. (well I tried it your version and it didn't work eather)

well anyway the problem is:

there are 30 lines if I do


purch.Lines.UserFields.Fields.Item("U_AnzVE").Value = "100";
purch.Lines.UserFields.Fields.Item("U_AnzPal").Value = "100";

where there should be only 10 lines!

I assure u It all works fine without these code-lines (but I need them:-))

Message was edited by: Andreas Hauri

AdKerremans
Active Contributor
0 Kudos

Hi Andreas,

Is it possible to test this on another version of SBO?

It looks like a bug in SP01 PL04.

Regards

Ad

Former Member
0 Kudos

Im doing some tests now I'll inform you when Im done ... takes ages to downgrade:-)

oops was on the wrong pc...

its Andreas writing

Message was edited by: Manuel Grenacher

Former Member
0 Kudos

Ok here is what I did:

I deinstalled SAP

I reinstalled everything.

Installed SP 00 PL 11:

It worked...

Installed SP 01 PL 04 again:

It wokred...

thanks for your help but the problem soved it's selfe

Andreas

AdKerremans
Active Contributor
0 Kudos

Hi Andreas,

Your problem lies here

if (i != 10 - 1) {

purch.Lines.Add();

}

change it to

if (i != 0)

{

purch.Lines.Add();

}

The first line is always present, so you dont have to do it every line and move this code to the beginning of your for loop.

Regards

Ad