intacct / intacct-sdk-net

Official repository of the Sage Intacct SDK for .NET
https://developer.intacct.com/tools/sdk-net/
Apache License 2.0
31 stars 45 forks source link

Sage Intacct .NET SDK Classes #16

Closed jmawebtech closed 4 years ago

jmawebtech commented 6 years ago

Hi,

My goal is to strong type vendor XML into a class. What fields exist in the vendor object? Do you have an XSD file or a C# class? Here is my code:

` OnlineClient client = Client(Logger());

        ReadByQuery query = new ReadByQuery()
        {
            ObjectName = "VENDOR",
            PageSize = 1, // Keep the count to just 1 for the example
            Fields =
{
    "RECORDNO",
    "VENDORID",
    "NAME"
}
        };

        Task<OnlineResponse> task = client.Execute(query);
        task.Wait();
        OnlineResponse response = task.Result;
        Result result = response.Results[0];
        StringReader reader = new StringReader(result.Data[0].ToString());
        XmlSerializer xmlSerializer = new XmlSerializer(typeof(Vendor));
        Vendor data = (Vendor)xmlSerializer.Deserialize(reader);

`

jimmymcpeter commented 6 years ago

Unfortunately Intacct does not provide XSD for the responses. Leave out the Fields property on the ReadByQuery and you'll see all of the fields returned in whatever company you run this in (including custom fields). You can also run an inspect to get the object definition which is equivalent to going into Platform Services > Objects list and viewing the object itself in the UI.

TrustantialJake commented 6 years ago

I wanted to do this as well. What I ended up doing is just creating a class that just had the attributes that were returned from ReadByQuery. What would be nice in the future is if the abstract data classes had XMLAttributes on them and we could just deserialize to a concrete class of those.

cornmen commented 5 years ago

TrustantialJake, can you provide the code you created to get the attributes from the readbyquery into a class? I'm new to the Intacct .NET SDK and have no trouble with doing a read like they give in the examples but am not seeing a way from the readbyquery to getting the field values in each record returned. Thanks

SergioBAM commented 5 years ago

@cornmen What you can do in visual studio is paste_special from JSON/XML into a class.

Using postman, within your readbyquery add <returnFormat>json</returnFormat> (also add all fields and pagesize 1):

Copy the response. Create a new class in VS. Delete the public class YourClass { }.

Then go into Edit> Paste Special >Paste JSON as Classes. Rename the class and rootobject (rootobject would probably be the plural form of class). Also change the Class[ ] to a List.

jhorn70 commented 5 years ago

@cornmen, sorry it's been a while. What I did was this. Below is example of a class for customer. It doesn't have all the columns, because I just needed those columns. You could abstract this more if you wanted to, but I didn't think it was worth it.

[Serializable()]
    [XmlRoot(ElementName = "customer")]
    public class IntacctCustomer
    {
        public int RECORDNO { get; set; }

        public string CUSTOMERID { get; set; }

        public string NAME { get; set; }

    }
}

Then after my ReadByQuery I did this:

ReadByQuery query = new ReadByQuery()
            {
                ObjectName = "CUSTOMER",
                PageSize = 1,
                Fields =
                {
                    "RECORDNO",
                    "CUSTOMERID",
                    "NAME"
                },
                Query = new EqualToString()
                {
                    Field = "CUSTOMERID",
                    Value = customerid
                }
            };

            try
            {
                Task<OnlineResponse> task = intacctClient.Execute(query);
                task.Wait(_intacctConfig.Timeout);
                OnlineResponse response = task.Result;
                Result result = response.Results[0];

                if (result.Count > 0)
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(IntacctCustomer));
                    var customer = (IntacctCustomer)serializer.Deserialize(result.Data.FirstOrDefault().CreateReader());

                    return customer;
                }
                else
                {
                    return null;
                }

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                throw;
            }
intacctcoleenho commented 4 years ago

This request has a customer provided work around (see comments above); closing issue.