Closed jmawebtech closed 4 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.
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.
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
@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.
@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;
}
This request has a customer provided work around (see comments above); closing issue.
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());
`