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.

  • 0 in reply to Russell Libby

    Hi  thank you... the Copy worked! Do you have an example of entering an AR Cash Receipt with the Deposit? using BOI c# (similar to what youve helped me on above :) ) thanks again , you have been my only hope!

  • +1 in reply to Anastasia Maher
    verified answer

    Hi Anastasia, Here is an A/R Cash Receipt example. Cash Receipts entry is a bit unique so hopefully this example will help.

    Thank you!

    using Sage100.ObjectManagement; /* https://www.nuget.org/packages/Sage100.ObjectManagement */
    using Sage100.ObjectManagement.Interfaces;
    using System;
    using System.Collections.Generic;
    using System.Net;
    
    namespace SageCityDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                var arDivNo = "01";
                var custNo = "ABF";
                var depositType = "C";
                var checkNo = "100111";
                var invoiceNo = "0000122";
                var depositAmt = 10.00;
                var postingAmt = 10.00;
                var amountPosted = 10.00;
    
                var sessionLogon = new SessionLogon
                {
                    CompanyCode = "ABC",
                    UserLogon = new NetworkCredential { UserName = "all", Password = "" },
                    ModuleCode = "A/R",
                    ModuleDate = DateTime.Today
                };
    
                using (IMasSession sySession = new MasSession(@"C:\Sage\Sage 100 Advanced\MAS90\Home"))
                {
                    try
                    {
                        sySession.InitSession(sessionLogon);
    
                        CI.ColumnNames.Add("AR_CashReceipts_bus", new Dictionary<string, string> { { CI.NextNumberMethod, "nGetNextReceiptNo" }, { CI.HeaderKeyColumns, "DepositNo$" } });
    
                        using (var arCashReceipts = sySession.CreateObject<ILineEntry>("AR_CashReceipts_bus", "AR_CashReceipts_ui", "A/R"))
                        using (var arCashReceiptsDeposit = sySession.CreateObject<IMasBusinessObject>("AR_CashReceiptsDeposit_bus", "AR_CashReceipts_ui", "A/R"))
                        {
                            // 1. Check batches on deposit object - this is unique to cash receipts. Usually batches are accessed via the ILineEntry (header) object.
                            var batchEnabled = ((int)arCashReceiptsDeposit.PvxObject.nBatchEnabled != 0);
                            if (batchEnabled)
                            {
                                var batchNo = string.Empty;
                                if ((int)arCashReceiptsDeposit.PvxObject.nSelectNewBatch(out batchNo, "N", "My New Batch") != 1) throw new ApplicationException($"Failed to create batch number. {arCashReceiptsDeposit.LastErrorMessage}");
                            }
    
                            // 2. Create the deposit record.
                            var depositNo = string.Empty;
                            arCashReceiptsDeposit.PvxObject.nGetNextDepositNo(out depositNo);
    
                            if (!arCashReceiptsDeposit.SetValue("DepositDesc$", "My Deposit")) throw new ApplicationException($"{arCashReceiptsDeposit.LastErrorMessage}");
                            if (!arCashReceiptsDeposit.SetValue("BankCode$", "D")) throw new ApplicationException($"{arCashReceiptsDeposit.LastErrorMessage}");
                            if (!arCashReceiptsDeposit.SetValue("CashDepositAmt", depositAmt)) throw new ApplicationException($"{arCashReceiptsDeposit.LastErrorMessage}");
    
                            if (!arCashReceiptsDeposit.Write()) throw new ApplicationException($"{arCashReceiptsDeposit.LastErrorMessage}");
    
                            // 3. Create Cash Receipt Header.
    
                            if (!arCashReceipts.SetKeyValue("DepositNo$", depositNo)) throw new ApplicationException($"{arCashReceipts.LastErrorMessage}");
                            if (!arCashReceipts.SetKeyValue("ARDivisionNo$", arDivNo)) throw new ApplicationException($"{arCashReceipts.LastErrorMessage}");
                            if (!arCashReceipts.SetKeyValue("CustomerNo$", custNo)) throw new ApplicationException($"{arCashReceipts.LastErrorMessage}");
                            if (!arCashReceipts.SetKeyValue("DepositType$", depositType)) throw new ApplicationException($"{arCashReceipts.LastErrorMessage}");
                            if (!arCashReceipts.SetKeyValue("CheckNo$", checkNo)) throw new ApplicationException($"{arCashReceipts.LastErrorMessage}");
                            if ((int)arCashReceipts.SetKey() == 0) throw new ApplicationException($"{arCashReceipts.LastErrorMessage}");
    
                            if (!arCashReceipts.SetValue("PostingAmt", postingAmt)) throw new ApplicationException($"{arCashReceipts.LastErrorMessage}");
    
                            // 4. Create Cash Receipt Lines.
    
                            if (!arCashReceipts.AddLine()) throw new ApplicationException($"{arCashReceipts.LastErrorMessage}");
    
                            if (!arCashReceipts.Lines.SetValue("InvoiceNo$", invoiceNo)) throw new ApplicationException($"{arCashReceipts.Lines.LastErrorMessage}");
                            if (!arCashReceipts.Lines.SetValue("AmountPosted", amountPosted)) throw new ApplicationException($"{arCashReceipts.Lines.LastErrorMessage}");
    
                            if (!arCashReceipts.Lines.Write()) throw new ApplicationException($"{arCashReceipts.Lines.LastErrorMessage}");
    
                            // 5. Write the header and commit the lines.
    
                            if (!arCashReceipts.Write()) throw new ApplicationException($"{arCashReceipts.LastErrorMessage}");
                        }
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.Message);
                    }
                }
            }
        }
    }
    

  • 0 in reply to Bret

    This worked beautifully!!! thank you so much Bret! Saved me so much time and headache.

  • 0 in reply to Anastasia Maher

    Bret, thanks for following up on this for me. Much appreciated.