Skip to Content

UDF value not set when the lines are from base document

I am trying to create a target document by specifying the base document keys in lines

Eg:

TargetDoc.Lines.BaseEntry = SourceDoc.Lies.DocEntry

TargetDoc.Lines.BaseType = SourceDoc.Lies.ObjType

TargetDoc.Lines.BaseLine = SourceDoc.Lies.LineNum

After setting these information, Im trying to set some of the UDF values in Header and line. Found that the UDFs values are not setting here.

Target document is a PO and base document is an SO. Document is created without errors but the UDF values are missing.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • Apr 11 at 10:28 AM

    Hi Sinoj George,

    This is the known scenario. You need to set the UDF values on the target document manually at the time of document creation.

    Refer to SAP Note 1382856 for the same.

    Kind regards,

    ANKIT CHAUHAN

    SAP Business One Support

    Add comment
    10|10000 characters needed characters exceeded

    • HI Ankit,

      I am setting the value in code. This is not shown in the document.

      "Im trying to set some of the UDF values in Header and line. Found that the UDFs values are not setting here."

  • Apr 11 at 10:36 AM

    Hi Sinoj George,

    Please help to share the screenshot about the UDF Details and the code which is being used.

    Kind regards,

    ANKIT CHAUHAN

    SAP Business One Support

    Add comment
    10|10000 characters needed characters exceeded

    • Did you read this line in my question?

      Is this somehow the reason?

      "Target document is a PO and base document is an SO. Document is created without errors but the UDF values are missing."

      I never tried before to link the PO to SO, but the document created is correct other than the UDF values.

  • Apr 15 at 02:04 PM

    Hi Sinoj George and Varnavas Eleftheriou,

    Please note that Procurement purchase documents are supported in Data Interface API (DI API) from SAP Business One Version 9.3 PL05.

    Refer to SAP Note 2654654 for the same.

    Kind regards,

    ANKIT CHAUHAN

    SAP Business One Support

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 12 at 06:15 AM

    Dear Sinoj George,

    Thanks for the update. Apologies for the inconvenience as i had not seen the 2nd comment you provided up there. The way you set your UDFs is correct. Consider the code below;

               SAPbobsCOM.Documents oDelivery;
                oDelivery = ((SAPbobsCOM.Documents)(Menu.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)));
                oDelivery.GetByKey(int.Parse(maxEntryAf));
    
    
                SAPbobsCOM.Documents oInvoice;
                oInvoice = ((SAPbobsCOM.Documents)(Menu.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)));
                
                oInvoice.CardCode = oDelivery.CardCode;
                oInvoice.CardName = oDelivery.CardName;
                oInvoice.DocDate = oDelivery.DocDate;
                oInvoice.DocDueDate = oDelivery.DocDueDate;
                oInvoice.TaxDate = oDelivery.TaxDate;
                oInvoice.Comments = oDelivery.Comments;
                oInvoice.UserFields.Fields.Item("U_BLT").Value = "Y";
                oInvoice.DocTotal = oDelivery.DocTotal;
                oInvoice.ContactPersonCode = oDelivery.ContactPersonCode;
             
    
    
                int rows = oDelivery.Lines.Count;
    
    
                for (int i = 0; i < rows; i++)
                {
                    oDelivery.Lines.SetCurrentLine(i);
                    oInvoice.Lines.ItemCode = oDelivery.Lines.ItemCode;
                    oInvoice.Lines.Quantity = oDelivery.Lines.Quantity;
                    oInvoice.Lines.UnitPrice =oDelivery.Lines.UnitPrice;
                    oInvoice.Lines.LineTotal =oDelivery.Lines.LineTotal;
               
                    oInvoice.Lines.Add();
                    
                }
    
    
                int ok = oInvoice.Add();
    
    
                if (ok != 0)
                {
                    string error = Menu.oCompany.GetLastErrorDescription();
                    Application.SBO_Application.MessageBox(error.ToString(), 1, "OK", "", "");
                }
                else
                {
                    Application.SBO_Application.MessageBox("Sales invoice added based on delivery:"+maxEntryAf);
    
    
                }
            }
    

    This way, you manually set each field instead of the whole line. It should work normally. Now, if you are setting the whole line as the base line, consider moving the setting of your UDFs after the copying of the lines. (there is a way to perform this; oInv.setDocumentLines(oDeliveryLines); but that worked in javascript for workflow.) By setting the fields one by one equal to your base document, it will not cause you any trouble as it is tested and working fine. Let us know if you need more help or your issue has been resolved!

    Sincerely,

    Varnavas Eleftheriou

    Add comment
    10|10000 characters needed characters exceeded

    • HI Varnavas Eleftheriou
      Thanks for your answer and you are right, if we set the base type, entry, line it will copy whole line to the target document. And I am able to do this even in the current case. But if i try to overwrite the value of those 2 UDF, that is not over written.

      Important, You cannot link the Sale's order on the Purchase Order.

      Now I am actually creating a PO and linking it to an SO (mentioned in the question). I too thought I cannot link these documents. But surprisingly, SAP DI API allows me to. So the PO becomes a procurement document that is linked to the sales order. This is the case where i am having this issue.

  • Apr 11 at 11:21 AM
    -1

    Dear Sinoj George,

    Following up on what Mr. ANKIT CHAUHAN had mentioned in his post. Quite an amazing guy and personality. Worked with him on incidents many times throughout my career. Anyway, what Mr. Chauhan is trying to say, is that you have to manually SET the target UDFs values = source UDFs values. In detail relative to your issue is the link he already provided. You need to add the following;

    TargetDoc.Lines.UserFields.Fields.Item("U_Test2").Value = SourceDoc.Lines.UserFields.Fields.Item("U_Test2").Value;

    It does not matter how many items you included, how many rows you have, how many times you duplicated or how you duplicated if you copied from or copied to or whatever the case was. Through DI API you have to SPECIFICALLY set the UDF values of the target document = with the udf of the source document. That is what Mr. ANKIT CHAUHAN is trying to tell you.

    Sincerely,

    Varnavas Eleftheriou

    Add comment
    10|10000 characters needed characters exceeded

    • Varnavas Eleftheriou I understand that clearly and i replied back to his answer that i am manually setting the value to the UDF's. Between, I am not expecting the values to be copied over from source document. I need new values to be set in the target document. In code I am doing that in the following way.

      I have also mentioned in the comment, the UDF values are not set ONLY IF I set the link to the base document.

      Which means in the code, if I comment out setting of the base information, the UDF values are set to the values.

      TargetDoc.Lines.UserFields.Fields.Item("U_SI_InterCo").Value = "Y"; //This is an alphanumeric UDF with valid value and default value
      
      TargetDoc.Lines.UserFields.Fields.Item("U_SI_IntcoDocType").Value = 17; //This is a numeric UDF with no valid or default value