This is a Sage cloud 2019 Business Object Interface question.
I'm experiencing issues trying to new up an AR_Customer_bus object, my eventual aim is to be able to create a new customer using the BOI. The error I'm getting is a 200 error.
Full disclosure; I'm a Sage BOI novice, although I'm a fairly seasoned developer and I don't have a Sage background but I do have the Sage BOI instructional materials. I have also posted this question on the Sage forum but the activity on the forums is pretty low so I'm covering my bases: https://www.sagecity.com/support_communities/sage100_erp/f/sage-100-business-object-interface/146142/unable-to-newobject-the-ar_customer_bus
Any assistance with this issue is greatly appreciated, it doesn't even have to be an exact solution, just general guidance that could help facilitate a solution would be greatly appreciated.
This is my code so far, also note that I've written this off the back of several examples I've found across my way:
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// Instantiate a ProvidexX.Script object and initialize with the path to MAS90\Home
using (DispatchObject pvx = new DispatchObject("ProvideX.Script"))
{
// Replace the text "*PATH TO MAS90\HOME*" with the correct MAS90\Home path in the line below
pvx.InvokeMethod("Init", @"[Correct path]");
// Instantiate a new Session object and initialize the session
// by setting the user, company, date and module
using (DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session")))
{
oSS.InvokeMethod("nLogon");
oSS.InvokeMethod("nSetUser", new object[] {"[Username]", "[Password]"});
oSS.InvokeMethod("nSetCompany", "[CompanyName]");
oSS.InvokeMethod("nSetDate", "A/R", "05312006");
oSS.InvokeMethod("nSetModule", "A/R");
// Get the Task ID for the AR_Customer_ui program
int TaskID = (int) oSS.InvokeMethod("nLookupTask", "AR_Customer_ui");
//int TaskID = (int)oSS.InvokeMethod("nLookupTask", "AR_Invoice_ui");
oSS.InvokeMethod("nSetProgram", TaskID);
CreateCustomer(pvx, oSS, out var customerNumber);
GetCustomerList(pvx, oSS, out var bob);
}
}
}
private static string CreateCustomer(DispatchObject pvx, DispatchObject oSS, out string customerNumber)
{
customerNumber = "";
using (DispatchObject oARCustomerEntry = new DispatchObject(pvx.InvokeMethod("NewObject", "AR_Customer_bus", oSS.GetObject()))) //Error 200 throw here.
{
try
{
object[] nextCustomerNumber = new object[] { "CustomerNo$" };
//Getting Next Customer Number
oARCustomerEntry.InvokeMethodByRef("nGetNextCustomerNo", nextCustomerNumber);
Console.WriteLine(nextCustomerNumber[0].ToString());
object retVal = 0;
retVal = oARCustomerEntry.InvokeMethodByRef("nSetKeyValue", new object[] { "ARDivisionNo$", "01" });
retVal = oARCustomerEntry.InvokeMethodByRef("nSetKeyValue", new object[] { "CustomerNo$", nextCustomerNumber[0].ToString() });
retVal = oARCustomerEntry.InvokeMethod("nSetKey");
Console.WriteLine(retVal.ToString());
retVal = oARCustomerEntry.InvokeMethodByRef("nSetValue", new object[] { "CustomerName$", "ROSE DAWSON" });
retVal = oARCustomerEntry.InvokeMethodByRef("nSetValue", new object[] { "AddressLine1$", "1234 LONG DREAM ST" });
retVal = oARCustomerEntry.InvokeMethodByRef("nSetValue", new object[] { "AddressLine2$", "" });
retVal = oARCustomerEntry.InvokeMethodByRef("nSetValue", new object[] { "AddressLine3$", "" });
retVal = oARCustomerEntry.InvokeMethodByRef("nSetValue", new object[] { "City$", "CITRUS HEIGHTS" });
retVal = oARCustomerEntry.InvokeMethodByRef("nSetValue", new object[] { "State$", "CA" });
Console.WriteLine(retVal.ToString());
retVal = oARCustomerEntry.InvokeMethodByRef("nSetValue", new object[] { "ZipCode$", "95621" });
retVal = oARCustomerEntry.InvokeMethodByRef("nSetValue", new object[] { "CountryCode$", "USA" });
retVal = oARCustomerEntry.InvokeMethodByRef("nSetValue", new object[] { "SalespersonDivisionNo$", "01" });
retVal = oARCustomerEntry.InvokeMethodByRef("nSetValue", new object[] { "SalespersonNo$", "RAP" });
Console.WriteLine(retVal.ToString());
retVal = oARCustomerEntry.InvokeMethod("nWrite");
if (retVal.ToString() == "0")
{
object errorMsg = oARCustomerEntry.GetProperty("sLastErrorMsg");
Console.WriteLine(errorMsg.ToString());
Console.Read();
}
customerNumber = nextCustomerNumber[0].ToString();
Console.WriteLine(retVal.ToString());
Console.Read();
}
catch (Exception ex)
{
object errorMsg = oARCustomerEntry.GetProperty("sLastErrorMsg");
Console.WriteLine(errorMsg.ToString());
Console.WriteLine(ex.Message);
Console.Read();
}
finally
{
oARCustomerEntry.Dispose();
}
}
return customerNumber;
}
Below is the line that throws the error:
public object GetObject()
{
return m_object;
}
Then it calls InvokeMethod which is shown below, this is exactly where the error 200 is thrown:
public object InvokeMethod(string sMethodName, params object[] aryParams)
{
return m_object.GetType().InvokeMember(sMethodName, m_flgMethod, null, m_object, aryParams);
}
My first thoughts were this is a permissions issue (since I had encountered that before, but the user that I'm setting has the role "Full Administrator" which when looking at the roles maintenance section of sage I can see that the role has every security permission assigned.
Please note: I have been able to new up other business objects like AR_DepositHistory_bus without a problem, and I've also managed to new up AR_Customer_ui and AR_Customer_svc so I don't know why this is a problem.
Here's the solution that worked for me
Solution 1 It took a while to get through this blocking issue but here's the resolution that worked for me:
Alternative solution
Cause The cause could be a couple of things:
I really hope this helps out others that hit against this same issue, from my understanding it's a fairly common one and one that took a long time to resolve.