cancel
Showing results for 
Search instead for 
Did you mean: 

UDF value not set when the lines are from base document

sg2707
Participant
0 Kudos

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.

Accepted Solutions (0)

Answers (5)

Answers (5)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

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

sg2707
Participant
0 Kudos

Does this copies the UDF info? im using 9.3 PL8

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

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

sg2707
Participant
0 Kudos

SAP version: SAP Business One 9.3 (9.30.150) PL: 05 (64-bit)

Im unable to upload the picture to your comment.

However when i dont set the base info and if the document is created as a new document the values are there.

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

sg2707
Participant
0 Kudos

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.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

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

sg2707
Participant

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."

ens_
Active Participant
0 Kudos

Dear sg2707,

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

sg2707
Participant
0 Kudos

Im sorry, but i dont understand what you mean by whole line here.

"This way, you manually set each field instead of the whole line"

Im setting each field, pasting again the sample i wrote in your comment.
Did you ever try this when creating Purchase order and link the line to the sales order line?

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
ens_
Active Participant
0 Kudos

Dear sg2707,

You are only providing me with the 2 lines that link the UDF. I cannot know what the rest is thats why i am trying to assume what you are running 🙂 Regardless, there is a way to create the target document based on the base document for all lines as they are. I will paste is in Javascript since i was working on Workflow scripting and i have it at hand right now

var quotation= CurrentProcess.B1Obj('dataObject3'); 
var lineCnt = quotation.getDocumentLines().size();
var OrderService = company.getBusinessService('17');
var OrderDoc = company.createDIObject('Document');
OrderDoc.setCardCode(CurrentProcess.DataObject('dataObject1').getItem('BPCode'));
var OrderLines = OrderDoc.getDocumentLines();
OrderLines = company.createDIObject('DocumentLines');


for(i=0; i<lineCnt; i++)
{
var OrderLine1= company.createDIObject('DocumentLine');
OrderLine1.setBaseType(23);
OrderLine1.setBaseEntry(CurrentProcess.DataObject('dataObject1').getItem('OQUT'));
OrderLine1.setBaseLine(i);
OrderLines.add(OrderLine1);
}
OrderDoc.setDocumentLines(OrderLines);
OrderService.add(OrderDoc);

The Lines here are copied as they are on the base document. That's how you set the whole line without specifying the fields one by one as i am doing on the code i provided on the previous comment.

Important, You cannot link the Sale's order on the Purchase Order. I have not tested it further than that. Technically, when you link documents, the base lines/document "locks" or "closes" as we say when it gets linked to the target document Sale's order → Invoice etc. If you want to copy them, use the code i provided where you set the fields one by one and the UDFs. Do NOT link the target lines with the base lines and you should be fine 🙂 Good Luck and have a great weekend ahead 🙂

Sincerely,

Varnavas Eleftheriou

sg2707
Participant

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.

ens_
Active Participant
0 Kudos

Dear sg2707,

Following up on what Mr. ankit.chauhan1 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.chauhan1 is trying to tell you.

Sincerely,

Varnavas Eleftheriou

sg2707
Participant
0 Kudos

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