Sage100.ObjectManagement Interfaces .net Error when creating line entry

SOLVED

   
           var sessionLogon = new SessionLogon
            {
                CompanyCode = companyCode,
                UserLogon = new NetworkCredential { UserName = userName, Password = password },
                ModuleCode = ModuleNames.AccountsReceivable,
                ModuleDate = DateTime.Today
            };




            using (var sySession = new MasSession(homePath))
            {
               sySession.InitSession(sessionLogon);


   
   
    using (var soInvoice = sySession.CreateObject<IMasBusinessObject>("SO_Invoice_bus", "SO_Invoice_ui", "S/O"))
            {

                soInvoice.SetValue("SalesPersonNo$", "0000");
                soInvoice.SetValue("SalesPersonDivisionNo$", "00");
                soInvoice.SetValue("ARDivisionNo$", "00");
                soInvoice.SetValue("InvoiceType$", "IN");
                soInvoice.SetValue("InvoiceNo$", "stapiIN");
                soInvoice.SetValue("InvoiceDate$", "20220710");
                soInvoice.SetValue("InvoiceDueDate$", "20220716");
                soInvoice.SetValue("DiscountDueDate$", "20220716");
                soInvoice.SetValue("TaxSchedule$", "DEFAULT");
                soInvoice.SetValue("OrderDate$", "20220502");
                soInvoice.SetValue("CustomerNo$", "0031330");
                soInvoice.SetValue("TermsCode$", "00");
                soInvoice.SetValue("OrderType$", "S");
                soInvoice.SetValue("PrintInvoice$", "N");
                soInvoice.SetValue("WarehouseCode$", "011");


                var soInvoiceLn = sySession.CreateObject<ILineEntry>("SO_InvoiceDetail_Bus", "SO_InvoiceDetail_Bus", "S/O");
                
                
            }
        }

Hello, we are getting an error when trying to create a line for a SO_Invoice using the Business Object dll in .net Sage100.ObjectManagementInterfaces

the error is  message attempted to perform an unauthorized operation.

  • +1
    verified answer

    Change the line of code that is failing to:

    var soInvoiceLn = sySession.CreateObject<ILineEntry>("SO_SalesOrder_bus", "SO_Invoice_ui", "S/O");

    Regards,
    Russell

  • 0 in reply to Russell Libby

    thank you! that worked! Do you know how i would link this LineEntry object to the Parent Invoice Header object?

                    using (var soInvoice = sySession.CreateObject<IMasBusinessObject>("SO_Invoice_bus", "SO_Invoice_ui", "S/O"))

                {

                    soInvoice.SetValue("SalesPersonNo$", "0000");

                    soInvoice.SetValue("SalesPersonDivisionNo$", "00");

                    soInvoice.SetValue("ARDivisionNo$", "00");

                    soInvoice.SetValue("InvoiceType$", "IN");

                    soInvoice.SetValue("InvoiceNo$", "stapiIN");

                    soInvoice.SetValue("InvoiceDate$", "20220710");

                    soInvoice.SetValue("InvoiceDueDate$", "20220716");

                    soInvoice.SetValue("DiscountDueDate$", "20220716");

                    soInvoice.SetValue("TaxSchedule$", "DEFAULT");

                    soInvoice.SetValue("OrderDate$", "20220502");

                    soInvoice.SetValue("CustomerNo$", "0031330");

                    soInvoice.SetValue("TermsCode$", "00");

                    soInvoice.SetValue("OrderType$", "S");

                    soInvoice.SetValue("PrintInvoice$", "N");

                    soInvoice.SetValue("WarehouseCode$", "011");

                      //  soInvoice.

                        

                   //var soInvoiceLn = sySession.CreateObject<ILineEntry>("SO_InvoiceDetail_Bus", "SO_InvoiceDetail_Bus", "S/O");

                        var soInvoiceLn = sySession.CreateObject<ILineEntry>("SO_SalesOrder_bus", "SO_Invoice_ui", "S/O");

                        //HERE how would i link the above soInvoiceLn to the SoInvoice object (header)

                        //    soInvoiceLn.Lines.SetKeyValue

                        // soInvoiceLn.AddLine();

                        if (!soInvoice.Write()) { Console.WriteLine($"New customer not created. {soInvoice.LastErrorMessage}"); }

  • +1 in reply to Anastasia Maher
    verified answer

                    using (var soInvoice = sySession.CreateObject<IMasBusinessObject>("SO_Invoice_bus", "SO_Invoice_ui", "S/O"))
                {
    
                    soInvoice.SetValue("SalesPersonNo$", "0000");
                    soInvoice.SetValue("SalesPersonDivisionNo$", "00");
                    soInvoice.SetValue("ARDivisionNo$", "00");
                    soInvoice.SetValue("InvoiceType$", "IN");
                    soInvoice.SetValue("InvoiceNo$", "stapiIN");
                    soInvoice.SetValue("InvoiceDate$", "20220710");
                    soInvoice.SetValue("InvoiceDueDate$", "20220716");
                    soInvoice.SetValue("DiscountDueDate$", "20220716");
                    soInvoice.SetValue("TaxSchedule$", "DEFAULT");
                    soInvoice.SetValue("OrderDate$", "20220502");
                    soInvoice.SetValue("CustomerNo$", "0031330");
                    soInvoice.SetValue("TermsCode$", "00");
                    soInvoice.SetValue("OrderType$", "S");
                    soInvoice.SetValue("PrintInvoice$", "N");
                    soInvoice.SetValue("WarehouseCode$", "011");
    
              
                        var soInvoiceLn = sySession.CreateObject<ILineEntry>("SO_SalesOrder_bus", "SO_Invoice_ui", "S/O");
    
                        //HERE how would i link the above soInvoiceLn to the SoInvoice object (header)
    
                 
    
                        if (!soInvoice.Write()) { Console.WriteLine($"New customer not created. {soInvoice.LastErrorMessage}"); }
                        
                        
                }

    here is a code snippet^^^ looking to add the lineentry attached to the invoice header above
    thank YOU so so much!!!! 

  • +1 in reply to Anastasia Maher
    verified answer

    Full example based on ABC demo data. Replace with your desired data.

            public void TestInvoice()
            {
                var sessionLogon = new SessionLogon
                {
                    CompanyCode = "ABC",
                    UserLogon = new NetworkCredential { UserName = "all", Password = "" },
                    ModuleCode = ModuleNames.SalesOrder,
                    ModuleDate = DateTime.Today
                };
    
                var lineData = new LineDetail[]
                {
                    new LineDetail { ItemCode = "6655", QuantityOrdered = 1 },
                    new LineDetail { ItemCode = "SPEAKERS", QuantityOrdered = 2 },
                    new LineDetail { ItemCode = "1001-HON-H252", QuantityOrdered = 3 }
                };
    
                using (var sySession = new MasSession(@"c:\sage\sage 100 standard\mas90\home"))
                {
                    sySession.InitSession(sessionLogon);
    
                    using (var soInvoice = sySession.CreateObject<ILineEntry>("SO_Invoice_bus", "SO_Invoice_ui", "S/O"))
                    {
                        if (soInvoice.BatchEnabled)
                        {
                            var batch = soInvoice.SelectBatch();
                        }
    
                        var invoiceNo = string.Empty;
    
                        soInvoice.PvxObject.nGetNextInvoiceNo(ref invoiceNo);
    
                        soInvoice.SetKey(invoiceNo); /* Or using a preset value soInvoice.SetKey("stapiIN"); */
                        soInvoice.SetValue("ARDivisionNo$", "01");
                        soInvoice.SetValue("CustomerNo$", "ABF");
                        soInvoice.SetValue("SalesPersonNo$", "0100");
                        soInvoice.SetValue("SalesPersonDivisionNo$", "01");
                        soInvoice.SetValue("InvoiceType$", "IN");
                        soInvoice.SetValue("InvoiceDate$", "20220710");
                        soInvoice.SetValue("InvoiceDueDate$", "20220716");
                        soInvoice.SetValue("DiscountDueDate$", "20220716");
                        soInvoice.SetValue("TaxSchedule$", "DEFAULT");
                        soInvoice.SetValue("OrderDate$", "20220502");
                        soInvoice.SetValue("TermsCode$", "00");
                        soInvoice.SetValue("OrderType$", "S");
                        soInvoice.SetValue("PrintInvoice$", "N");
                        soInvoice.SetValue("WarehouseCode$", "011");
    
                        foreach (var line in lineData)
                        {
                            soInvoice.AddLine();
    
                            Trace.WriteLine(soInvoice.Lines.GetKey());
    
                            soInvoice.Lines.SetValue("ItemCode", line.ItemCode);
                            soInvoice.Lines.SetValue("QuantityOrdered", line.QuantityOrdered);
                            soInvoice.Lines.Write();
                        }
    
                        soInvoice.Write();
                    }
                }
            }

  • 0 in reply to Russell Libby

    awesome!!! Your are a LIFE SAVER!!!! cannot thank you enough!

  • 0 in reply to Anastasia Maher

    Hi Anastasia, happy to see that the community helped you figure out a solution!Tada 

    If you have a minute, tell us about your great experience on Sage City, take this short 3 question survey

  • 0 in reply to Erzsi_I

    Hello - thank you so much for your help! Do you have an example of the Split Commissions entry and link to the SoInvoice?

    for this same business object how would I add a split commissions for the salesperson?

    I can only see the below two fields, but what if i have 2 sales persons and need to split the commissions? do you have an example of adding this to an SO_Invoice? 

    soInvoice.SetValue("SalesPersonNo$", "0000");
    soInvoice.SetValue("SalesPersonDivisionNo$", "00");

  • +1 in reply to Anastasia Maher
    verified answer

                    using (var soInvoice = sySession.CreateObject<ILineEntry>("SO_Invoice_bus", "SO_Invoice_ui", "S/O"))
                    {
                        if (soInvoice.BatchEnabled)
                        {
                            var batch = soInvoice.SelectBatch();
                        }
    
                        var invoiceNo = string.Empty;
    
                        soInvoice.PvxObject.nGetNextInvoiceNo(ref invoiceNo);
    
                        soInvoice.SetKey(invoiceNo);
    
                        soInvoice.SetValue("ARDivisionNo$", "01");
                        soInvoice.SetValue("CustomerNo$", "ABF");
                        soInvoice.SetValue("SalesPersonNo$", "0100");
                        soInvoice.SetValue("SalesPersonDivisionNo$", "01");
                        soInvoice.SetValue("InvoiceType$", "IN");
                        soInvoice.SetValue("InvoiceDate$", "20220710");
                        soInvoice.SetValue("InvoiceDueDate$", "20220716");
                        soInvoice.SetValue("DiscountDueDate$", "20220716");
                        soInvoice.SetValue("TaxSchedule$", "DEFAULT");
                        soInvoice.SetValue("OrderDate$", "20220502");
                        soInvoice.SetValue("TermsCode$", "00");
                        soInvoice.SetValue("OrderType$", "S");
                        soInvoice.SetValue("PrintInvoice$", "N");
                        soInvoice.SetValue("WarehouseCode$", "011");
    
                        /* Set split commission */
                        soInvoice.SetValue("SplitCommissions$", "Y");
    
                        soInvoice.SetValue("SalespersonDivisionNo2$", "01");
                        soInvoice.SetValue("SalespersonNo2$", "0200");
                        soInvoice.SetValue("SplitCommRate2", 20);
    
                        foreach (var line in lineData)
                        {
                            soInvoice.AddLine();
    
                            Trace.WriteLine(soInvoice.Lines.GetKey());
    
                            soInvoice.Lines.SetValue("ItemCode", line.ItemCode);
                            soInvoice.Lines.SetValue("QuantityOrdered", line.QuantityOrdered);
                            soInvoice.Lines.Write();
                        }
    
                        soInvoice.Write();
                    }

  • 0 in reply to Russell Libby

    Thank you Russell!! you have been huge help. Do you have an example of PO Entry? were getting invalid or missing header error

    using (var sySession = new MasSession(homePath))
                {
                    sySession.InitSession(sessionLogon);
    
                    CI.ColumnNames.Add("PO_PURCHASEORDER_BUS", new Dictionary<string, string> { { CI.NextNumberMethod, "nGetNextPurchaseOrderNo" }, { CI.HeaderKeyColumns, "PurchaseOrderNo$" } });
                    using (var poEntry = sySession.CreateObject<ILineEntry>("PO_PurchaseOrder_bus", "PO_PurchaseOrder_ui", "P/O"))
                    {
    
       var nextOrderNo = poEntry.GetNextDocumentNumber();
    
                        poEntry.SetKeyValue("PurchaseOrderNo", nextOrderNo);
                          poEntry.SetValue("PurchaseOrderDate", "20231101");
                          poEntry.SetValue("OrderType", "S");
                        poEntry.SetValue("APDivisionNo", "00");
                        poEntry.SetValue("VendorNo", "0008000");
    
                        poEntry.AddLine();
    
                        Trace.WriteLine(poEntry.Lines.GetKey());
    
                        poEntry.Lines.SetValue("ItemCode", "1001-HON-H252");
                        poEntry.Lines.SetValue("QuantityOrdered", 2);
    
                        poEntry.Lines.Write();
                        poEntry.Write();
                        
                        }
                        }

  • 0 in reply to Anastasia Maher

    Change the following line:

    -> poEntry.SetKeyValue("PurchaseOrderNo", nextOrderNo);

    to

    -> poEntry.SetKey(nextOrderNo);