Acumatica 通过web服务从采购订单创建采购收据

Acumatica 通过web服务从采购订单创建采购收据,acumatica,Acumatica,我们正在尝试创建链接到采购订单文档的采购订单接收文档。下面是代码,但在提交选择的采购订单行后,Web服务不会返回任何结果。之后,它会给出一个执行超时异常 apitest.Screen context = BuisnessLogicACU.context; PO302000Content PORcptSchema; try { PORcptSchema = context.PO302000GetSchema()

我们正在尝试创建链接到采购订单文档的采购订单接收文档。下面是代码,但在提交选择的采购订单行后,Web服务不会返回任何结果。之后,它会给出一个执行超时异常

        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];
apitest.Screen context=BuisnessLogicACU.context;
PO302000内容模式;
尝试
{
PorctSchema=context.PO302000GetSchema();
}
抓住
{
BuisnessLogicACU.contextLogin();
PorctSchema=context.PO302000GetSchema();
}
PorctSchema.Actions.AddPOOrderLine2.Commit=true;
//标题
AcumaticaInterface.apitest.Command[]文档=新建AcumaticaInterface.apitest.Command[]
{                    
PorctSchema.Actions.Insert,
新价值
{
值=BPCode,
LinkedCommand=PorctSchema.DocumentSummary.Vendor,
提交=真
},
新价值
{
值=BPRefNbr,
LinkedCommand=PorctSchema.DocumentSummary.VendorRef
},
新价值
{
Value=PostDate.HasValue?((DateTime)PostDate.Value)。ToLongDateString():“”,
LinkedCommand=PorctSchema.DocumentSummary.Date
},                   
新价值
{
Value=DocDate.HasValue?((DateTime)DocDate.Value)。ToLongDateString():“”,
LinkedCommand=PorctSchema.DocumentSummary.Date
},
新价值
{
值=描述,
LinkedCommand=PorctSchema.DocumentSummary.NoteText
},
新价值
{
Value=“POS Doc”+DocNum,
LinkedCommand=PorctSchema.DocumentSummary.VendorRef
},
};
//设置对话框的答案
var dgAnswer=新命令[]
{新值
{
Value=“确定”,
LinkedCommand=PorctSchema.AddPurchaseOrderLine.ServiceCommands.DialogAnswer,
提交=真
}
};
Document=Document.Concat(dgAnswer.ToArray();
//选线
foreach(POReceiptLine.OrderBy(x=>x.LineNum)中的POReceiptLine行)
{
AcumaticaInterface.apitest.Command[]Docline=新建AcumaticaInterface.apitest.Command[]
{                   
新钥匙
{
ObjectName=PorctSchema.AddPurchaseOrderLine.OrderNbr.ObjectName,
FieldName=PorctSchema.AddPurchaseOrderLine.OrderNbr.FieldName,
Value=“=”+line.BaseDocNum+“”
},
新钥匙
{
ObjectName=PorctSchema.AddPurchaseOrderLine.LineNbr.ObjectName,
FieldName=PorctSchema.AddPurchaseOrderLine.LineNbr.FieldName,
Value=“=”+line.BaseLineNum+“”
},              
新价值
{
Value=“True”,
LinkedCommand=PorctSchema.AddPurchaseOrderLine.Selected,
提交=真
}  
};
Document=Document.Concat(Docline.ToArray();
}
//添加采购订单行。
var addPOLine=new命令[]
{ 
PorctSchema.Actions.AddPOOrderLine2,
////返回网格中添加的线
PorctSchema.DocumentDetails.POOrderNbr,
PORcptSchema.DocumentDetails.POLineNbr
};
Document=Document.Concat(addPOLine.ToArray();
var receiptLines=context.po302000提交(文档);
//更新数量。。
//检查webservice演示中的CreateShipping()
List commandList=新列表();
for(int index=0;indexx.BaseDocNum==receiptline[index]。DocumentDetails.POOrderNbr.Value&&x.BaseLineNum.ToString()==receiptline[index]。DocumentDetails.POLineNbr.Value)。FirstOrDefault();
如果(行!=null)
{
commandList.Add(新值
{
值=行数量ToString(),
LinkedCommand=PorctSchema.DocumentDetails.ReceiptQty,
提交=索引<接收行.长度-1
});
}
其他的
抛出新异常(“未找到匹配的POS Rcpt行”);
}
//拯救
AcumaticaInterface.apitest.Command[]保存=新建AcumaticaInterface.apitest.Command[]{
PORcptSchema.Actions.Save
};
Document=Document.Concat(save.ToArray();
//保存并获取文档编号
AcumaticaInterface.apitest.Command[]输出=新的AcumaticaInterface.apitest.Command[]{
PorctSchema.DocumentSummary.Type,
PORcptSchema.DocumentSummary.ReceiptNb
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,
};
var addPOLineWithCommit = PORcptSchema.Actions.AddPOOrderLine;
addPOLineWithCommit.Commit = true;
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];           
    }