2017-01-16 87 views
0

我們正在嘗試創建鏈接到採購訂單文檔的採購訂單收貨憑證。以下是代碼,但在提交PO行的選擇後,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]; 

在此特定行之後,web服務未返回任何結果。任何人都可以提供幫助嗎?

變種receiptLines = context.PO302000Submit(文檔);

+0

我只想指出,在創建Document命令數組時,您的第三個和第七個命令都是VendorRef字段的設置值。同樣的事情發生在你的第四和第五個命令中,這兩個命令都爲Date字段設置了一個值。 – samol518

+0

是的,謝謝指出。 – Hybridzz

回答

0

@ samol518的樣品幫助我解決。我張貼的全部代碼,如果有人以後需要它

下面的代碼會從PO,變化量增加線路和保存PO收據。

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

該解決方案是使用Acumatica版本6.00.1596測試。

我發現返回的採購訂單行的值,你不需要做一個foreach。

設置彙總值並刪除這裏的deuplicate後是我用它來找回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, 
}; 

隨着 「addPOLineWithCommit」 定義爲

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

使用這些行: VAR receiptLines = context.PO302000Submit(文檔); 正在返回一些關於可用行的信息。

+0

您的部分代碼有助於解決問題。我將發佈完整的工作代碼。 – Hybridzz