Sin
Sin

Reputation: 1864

Create Purchase receipt from Purchase order through web service

We are trying to create a PO receipt document that is linked to a PO document. Below is the code, but after submitting the selection of PO lines, the webservice not returning any results. Later it gives an execution time out exception.

        apitest.Screen context = BuisnessLogicACU.context;
        PO302000Content PORcptSchema;
        try
        {
            PORcptSchema = context.PO302000GetSchema();
        }
        catch
        {
            BuisnessLogicACU.contextLogin();
            PORcptSchema = context.PO302000GetSchema();
        }
        PORcptSchema.Actions.AddPOOrderLine2.Commit = true;
       //header            
            AcumaticaInterface.apitest.Command[] Document = new AcumaticaInterface.apitest.Command[]
            {                    
                PORcptSchema.Actions.Insert,
                 new Value
                {
                    Value = BPCode,
                    LinkedCommand = PORcptSchema.DocumentSummary.Vendor,
                    Commit = true
                },
                 new Value
                {
                    Value = BPRefNbr ,
                    LinkedCommand = PORcptSchema.DocumentSummary.VendorRef
                },
                 new Value
                {
                    Value = PostDate.HasValue ? ((DateTime)PostDate.Value).ToLongDateString() : "",
                    LinkedCommand = PORcptSchema.DocumentSummary.Date
                },                   
                 new Value
                {
                    Value = DocDate.HasValue ? ((DateTime)DocDate.Value).ToLongDateString() : "",
                    LinkedCommand = PORcptSchema.DocumentSummary.Date
                },
                 new Value
                {
                    Value = Description,
                    LinkedCommand = PORcptSchema.DocumentSummary.NoteText
                },
                new Value
                {
                    Value = "POS Doc " + DocNum,
                    LinkedCommand = PORcptSchema.DocumentSummary.VendorRef
                },

            };



//set the dialog answer
            var dgAnswer = new Command[]
                        { new Value 
                            {
                                Value = "OK", 
                                LinkedCommand = PORcptSchema.AddPurchaseOrderLine.ServiceCommands.DialogAnswer, 
                                Commit = true 
                            }
                        };
            Document = Document.Concat(dgAnswer).ToArray();


 //select lines
            foreach (POReceiptLine line in POReceiptlines.OrderBy(x => x.LineNum))
            {
                AcumaticaInterface.apitest.Command[] Docline = new AcumaticaInterface.apitest.Command[]
                {                   
                    new Key
                    {
                        ObjectName = PORcptSchema.AddPurchaseOrderLine.OrderNbr.ObjectName,
                        FieldName = PORcptSchema.AddPurchaseOrderLine.OrderNbr.FieldName,
                        Value = "='" + line.BaseDocNum + "'"
                    },
                    new Key
                    {
                        ObjectName = PORcptSchema.AddPurchaseOrderLine.LineNbr.ObjectName,
                        FieldName = PORcptSchema.AddPurchaseOrderLine.LineNbr.FieldName,
                        Value = "='" + line.BaseLineNum + "'"
                    },              
                    new Value 
                    {
                        Value = "True", 
                        LinkedCommand = PORcptSchema.AddPurchaseOrderLine.Selected, 
                        Commit = true 
                    }  
                };
                Document = Document.Concat(Docline).ToArray();
            }

  //Add PO line. 
            var addPOLine = new Command[]
                        { 
                            PORcptSchema.Actions.AddPOOrderLine2,

                            ////get back the added lines in the grid
                            PORcptSchema.DocumentDetails.POOrderNbr,
                            PORcptSchema.DocumentDetails.POLineNbr
                        };
            Document = Document.Concat(addPOLine).ToArray();

            var receiptLines = context.PO302000Submit(Document);
//update quantity..
            //check CreateShipment() in webservice demo
            List<Command> commandList = new List<Command>();
            for (int index = 0; index < receiptLines.Length; index++)
            {
                commandList.Add(new Value
                {
                    Value = index.ToString(),
                    LinkedCommand = PORcptSchema.DocumentDetails.ServiceCommands.RowNumber
                });

                POReceiptLine line = POReceiptlines.Where(x => x.BaseDocNum == receiptLines[index].DocumentDetails.POOrderNbr.Value && x.BaseLineNum.ToString() == receiptLines[index].DocumentDetails.POLineNbr.Value).FirstOrDefault();
                if (line != null)
                {
                    commandList.Add(new Value
                    {
                        Value = line.Qty.ToString(),
                        LinkedCommand = PORcptSchema.DocumentDetails.ReceiptQty,
                        Commit = index < receiptLines.Length - 1
                    });
                }
                else
                    throw new Exception("Matching POS Rcpt line not found.");
            }


            //save
            AcumaticaInterface.apitest.Command[] save = new AcumaticaInterface.apitest.Command[] {
                        PORcptSchema.Actions.Save
                    };
            Document = Document.Concat(save).ToArray();

            //SAVING And get the document nbr
            AcumaticaInterface.apitest.Command[] Output = new AcumaticaInterface.apitest.Command[] {                 
                PORcptSchema.DocumentSummary.Type,
                PORcptSchema.DocumentSummary.ReceiptNbr               
            };
            Document = Document.Concat(Output).ToArray();

           var POReceipt = context.PO302000Submit(Document)[0];

After this particular line, web service is not returning any results. Anyone can assist on this?

var receiptLines = context.PO302000Submit(Document);

Upvotes: 0

Views: 402

Answers (3)

Sandip K
Sandip K

Reputation: 1

This code is working, Receipt is creating but new created receipt is not generated for newley generated Purchase order, this receipt is generated for old any PO

Upvotes: 0

Sin
Sin

Reputation: 1864

@samol518's sample assisted me to resolve. I am posting the full code, if anyone later needs it

the below code will add lines from PO, change quantity and save the PO receipt.

public void createAcuPR()
    {

        apitest.Screen context = BuisnessLogicACU.context;
        PO302000Content PORcptSchema;
        try
        {
            PORcptSchema = context.PO302000GetSchema();
        }
        catch
        {
            BuisnessLogicACU.contextLogin();
            PORcptSchema = context.PO302000GetSchema();
        }
        var addPOLineWithCommit = PORcptSchema.Actions.AddPOOrderLine;
        addPOLineWithCommit.Commit = true;

        //somehow if there is a second document then it goes to update mode
        context.PO302000Submit(new Command[] { PORcptSchema.Actions.Insert });

        //header            
        AcumaticaInterface.apitest.Command[] Document = new AcumaticaInterface.apitest.Command[]
        {                
            PORcptSchema.Actions.Insert,
             new Value
            {
                Value = BPCode,
                LinkedCommand = PORcptSchema.DocumentSummary.Vendor,
                Commit = true
            },
             new Value
            {
                Value = BPRefNbr ,
                LinkedCommand = PORcptSchema.DocumentSummary.VendorRef
            },
             new Value
            {
                Value = PostDate.HasValue ? ((DateTime)PostDate.Value).ToLongDateString() : "",
                LinkedCommand = PORcptSchema.DocumentSummary.Date
            },               
             new Value
            {
                Value = "POS Doc " + DocNum + "-" + Description,
                LinkedCommand = PORcptSchema.DocumentSummary.NoteText
            }                               
        };

        //set the dialog answer
        var dgAnswer = new Command[]
                    { new Value 
                        {
                            Value = "OK", 
                            LinkedCommand = PORcptSchema.AddPurchaseOrderLine.ServiceCommands.DialogAnswer, 
                            Commit = true 
                        }
                    };
        Document = Document.Concat(dgAnswer).ToArray();

        //select lines from smart panel
        foreach (POReceiptLine line in POReceiptlines.OrderBy(x => x.LineNum))
        {
            AcumaticaInterface.apitest.Command[] Docline = new AcumaticaInterface.apitest.Command[]
            {                   
                new Key
                {
                    ObjectName = PORcptSchema.AddPurchaseOrderLine.OrderNbr.ObjectName,
                    FieldName = PORcptSchema.AddPurchaseOrderLine.OrderNbr.FieldName,
                    Value = "='" + line.BaseDocNum + "'"
                },
                new Key
                {
                    ObjectName = PORcptSchema.AddPurchaseOrderLine.LineNbr.ObjectName,
                    FieldName = PORcptSchema.AddPurchaseOrderLine.LineNbr.FieldName,
                    Value = "='" + line.BaseLineNum + "'"
                },              
                new Value 
                {
                    Value = "True", 
                    LinkedCommand = PORcptSchema.AddPurchaseOrderLine.Selected, 
                    Commit = true 
                }  
            };
            Document = Document.Concat(Docline).ToArray();
        }


        //Add PO line and retrive back the added lines.
        var addPOLine = new Command[]
                    {                             
                        addPOLineWithCommit,
                        ////get back the added lines in the grid
                        PORcptSchema.DocumentDetails.POOrderNbr,
                        PORcptSchema.DocumentDetails.POLineNbr
                    };
        Document = Document.Concat(addPOLine).ToArray();

        var receiptLines = context.PO302000Submit(Document);

        //update quantity..           
        List<Command> commandList = new List<Command>();
        for (int index = 0; index < receiptLines.Length; index++)
        {
            commandList.Add(new Value
            {
                Value = index.ToString(),
                LinkedCommand = PORcptSchema.DocumentDetails.ServiceCommands.RowNumber
            });

            POReceiptLine line = POReceiptlines.Where(x => x.BaseDocNum == receiptLines[index].DocumentDetails.POOrderNbr.Value && x.BaseLineNum.ToString() == receiptLines[index].DocumentDetails.POLineNbr.Value).FirstOrDefault();
            if (line != null)
            {
                commandList.Add(new Value
                {
                    Value = line.Qty.ToString(),
                    LinkedCommand = PORcptSchema.DocumentDetails.ReceiptQty,
                    Commit = index < receiptLines.Length - 1
                });
            }
            else
                throw new Exception("Matching POS Rcpt line not found.");
        }

        //save
        commandList.AddRange(
                    //SAVING And get the document nbr
                   new AcumaticaInterface.apitest.Command[] {   
                        PORcptSchema.Actions.Save,
                        PORcptSchema.DocumentSummary.Type,
                        PORcptSchema.DocumentSummary.ReceiptNbr               
        });


        var POReceipt = context.PO302000Submit(commandList.ToArray())[0];           
    }

Upvotes: 0

samol518
samol518

Reputation: 1404

This solution was tested using Acumatica version 6.00.1596.

I found that to return the value of the Purchase Order Lines, you do not need to do a foreach.

After setting the value for the summary and removing the deuplicate here is what I use to get back the POLines.

var selectPOLine = new Command[]
{
    new Value
    {
        Value = "OK",
        LinkedCommand = PORcptSchema.AddPurchaseOrderLine.ServiceCommands.DialogAnswer,
        Commit = true
    },
    addPOLineWithCommit,
    new Value
    {
        LinkedCommand = PORcptSchema.AddPurchaseOrderLinePOSelection.OrderNbr,
        Value = "PO000451"
    },
    new Value
    {
        Value = "True",
        LinkedCommand = PORcptSchema.AddPurchaseOrderLine.Selected,
    },
    PORcptSchema.AddPurchaseOrderLine.InventoryID,
    PORcptSchema.AddPurchaseOrderLine.LineDescription,
    PORcptSchema.AddPurchaseOrderLine.LineType,
};

With "addPOLineWithCommit" define as

var addPOLineWithCommit = PORcptSchema.Actions.AddPOOrderLine;
addPOLineWithCommit.Commit = true;

Using these the line : var receiptLines = context.PO302000Submit(Document); was returning me some information on available lines.

Upvotes: 1

Related Questions