【问题标题】:Create Purchase receipt from Purchase order through web service通过 Web 服务从采购订单创建采购收据
【发布时间】:2017-05-31 04:56:47
【问题描述】:

我们正在尝试创建链接到 PO 文档的 PO 收据文档。下面是代码,但是在提交订单行的选择后,webservice 没有返回任何结果。后来它给出了一个执行超时异常。

        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];

在此特定行之后,Web 服务未返回任何结果。任何人都可以在这方面提供帮助吗?

var receiptLines = context.PO302000Submit(Document);

【问题讨论】:

  • 我只想指出,在创建文档命令数组时,您的第三个和第七个命令都在为 VendorRef 字段设置值。同样的事情发生在你的第四个和第五个命令上,它们都在为日期字段设置一个值。
  • 是的,感谢您的指出。

标签: acumatica


【解决方案1】:

此解决方案已使用 Acumatica 版本 6.00.1596 进行了测试。

我发现要返回采购订单行的值,您不需要执行 foreach。

设置摘要的值并在此处删除重复数据后,我使用它来取回 POLine。

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,
};

用“addPOLineWithCommit”定义为

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

使用这些行: var receiptLines = context.PO302000Submit(Document); 正在向我返回一些关于可用线路的信息。

【讨论】:

  • 您的部分代码有助于解决问题。我将发布完整的工作代码。
【解决方案2】:

@samol518 的样本帮助我解决了问题。我正在发布完整的代码,如果以后有人需要它

下面的代码将从采购订单中添加行,更改数量并保存采购订单收据。

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];           
    }

【讨论】:

    【解决方案3】:

    此代码有效,正在创建收据,但未为新生成的采购订单生成新创建的收据,此收据是为旧的任何 PO 生成的

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    • 这并不能真正回答问题。如果您有其他问题,可以点击 提问。要在此问题有新答案时收到通知,您可以follow this question。一旦你有足够的reputation,你也可以add a bounty 来引起对这个问题的更多关注。 - From Review
    猜你喜欢
    • 2018-09-27
    • 2021-10-09
    • 2022-11-19
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多