cancel
Showing results for 
Search instead for 
Did you mean: 

oOrders Update() - error 1004

Lech
Discoverer
0 Kudos

Hi Everyone

To our application we are importing the Sale Order created in SAP.
When Sale Order is filled and ready to be send we are creating delivery document and sending it to SAP.
If one of the conditions is meet, I want to update the oOrders, one user field with value "Y". But when Update() is called I am getting error -1004 (the field I am trying to pass that value have not defined valid values). Below sample of the code.

 

//Update SAP
int erpDocEntry = mHelper.ConvertToInt32(dt.Rows[0]["ERP_DocEntry"]);
int erpDocLine = mHelper.ConvertToInt32(dt.Rows[0]["ERP_LineNum"]);

SAPbobsCOM.Documents sapSo = mObjects.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
sapSo.GetByKey(erpDocEntry);
if (sapSo != null && sapSo.Lines.Count > 0)
{
    for (int j = 0; j < sapSo.Lines.Count; j++)
    {
        sapSo.Lines.SetCurrentLine(j);
        if (sapSo.Lines.LineNum == erpDocLine)
        {
            sapSo.Lines.UserFields.Fields.Item("U_DEM_NA").Value = "Y";
            int errUpdatingSO = sapSo.Update();
            if (errUpdatingSO != 0)
            {
               ErrCode = RetVal;
               mObjects.oCompany.GetLastError(out errUpdatingSO, out ErrMsg);
               TransLog.Fail((ErrMsg));
               Logger.Error(_retValue);
            }
            break;
        }
    }
}

Error at line 15: sapSo.Update();
error 1004

Also, I am new here and posting this here in the ERP Q&A.
Could you please confirm this is the best place to post questions with this subject?
And if there is a better place, can you please give details where.
Thanks all.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Lech,

Yes, it is the correct place to post your question related to SAP Business One.

Can you please help to share the error message which you are getting?

You can get it using: string Error = oCompany.GetLastErrorDescription();

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

View Entire Topic
Lech
Discoverer
0 Kudos

I added what you asked for

Lech_0-1709216776895.png

This error message is about user defined field in the ORDR table, but in my original code i am trying to update value in the user defined field "U_DEM_NA" in the RDR1 table, which I am accessing from the ORDR object.

Am I right thinking I should first confirm I am setting the correct line when:
sapSo.Lines.SetCurrentLine(j);

Or can you see something else I cant?
Thank you very much for your help.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Lech,

From the first glance, there seems nothing wrong with your code.

To confirm, try to update any other field on header for example: NumAtCard property in DI code (Customer Ref. No. on Sales Order form) and check whether you have the same error message.

If yes, I feel that it is caused by some DB corruption.

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

Lech
Discoverer
0 Kudos

Hey Ankit

What I did I commented the line where trying to update value.
So what is really happening is I am getting the sale order object, not changing any values and updating it.
But this gives the same error

Lech_0-1709225710165.png

For now, thanks for your help. I will try something else or with different database.
Thanks again.