DispatchObject C# example not returning expected column

I'm new to Sage and I've been working on a sample app using DispatchObject.  The goal will be to eventually pull and push data GL entries.  I changed the sample to return AddressLine1, however; the sample only returns the customer number.

            // Instantiate a ProvidexX.Script object and initialize with the path to MAS90\Home
            using (DispatchObject pvx = new DispatchObject("ProvideX.Script"))
            {
                pvx.InvokeMethod("Init", masHomePath);

                // 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("nSetCompany", company);
                    oSS.InvokeMethod("nSetUser", userName, password);
                    oSS.InvokeMethod("nSetDate", "A/R", DateTime.Now.ToString("yyyyMMdd"));
                    oSS.InvokeMethod("nSetModule", "A/R");

                    // Get the Task ID for the AR_Customer_ui program
                    int TaskID = (int)oSS.InvokeMethod("nLookupTask", "AR_Customer_ui");
                    oSS.InvokeMethod("nSetProgram", TaskID);

                    using (DispatchObject dispatchObject = new DispatchObject(pvx.InvokeMethod("NewObject", "AR_Customer_svc", oSS.GetObject())))
                    {
                        String columns = "CustomerName$";
                        String keys = "CustomerNo$";
                        String returnFields = "AddressLine1$";
                        String returnAccountKeys = "AddressLine1$";
                        String whereClause = "CustomerName$=" + Convert.ToChar(34) + "Customer 1" + Convert.ToChar(34);

                        // Setup the parameter list to be passed as reference to the GetResultSets method
                        object[] getResultSetParams = new object[] { columns, keys, returnFields, returnAccountKeys, whereClause, "", "" };

                        // Call the GetResultSets to return the list of Customer numbers and names
                        dispatchObject.InvokeMethodByRef("nGetResultSets", getResultSetParams);
                        
                        // The ProvideX SEP character is referenced by character number 352 within C#
                        // Split the customer names into string array and list them in a console window
                        string[] names = getResultSetParams[2].ToString().Split(System.Convert.ToChar(352));
                        for (int x = 1; x < names.Length - 1; x++) System.Console.WriteLine("Name " + x.ToString() + ": " + names[x]);
                    }
                }

  • 0

    Hello GaryV,

    It doesn't look like you are selecting the "AddressLine1$" field in your "colums" variable. Have you tried that? I just ran a quick test, switching "CustomerName$" for "AddressLine1$" and I am getting the address returned to me (Still being selected by the CustomerName where clause).

    Adding "AddressLine1$" to the colums string returns an object like:

    [0] "AddressLine1$"

    [1] "CustomerNo$"

    [2] Customer Address1 Value

    [3] Customer Number Value

    Adding on to this;

    I just set up basic characters before hand for quotes and the seperator character, so I don't have to constantly Convert.Tochar

    If you want to select multiple fields in your "columns" string, you would format it like:

    char QUO = Convert.ToChar(34);

    string columns = "AddressLine1$+" + QUO + "," + QUO + "+AddressLine2$";

    This would cause your getResultSetParams[2] to return AddressLine1Value,AddressLine2Value