EventDay / Infusionsoft.net

A C# Wrapper around the Infusionsoft.com API
15 stars 22 forks source link

Getting CustomFields #25

Closed simonlongson closed 9 years ago

simonlongson commented 9 years ago
var ISContact = InfusionActions.GET_ContactByEmail("test@test.com", new[] {"_Status"});
foreach (var item in ISContact)
{
    Console.WriteLine(item.CustomFields["_Status"]);
}

That in a nut shell will query contact table using the email and return _Status back. Now when I run it I can see in the response the customField but I can't select it. I'm I doing something daft?

simonlongson commented 9 years ago

For now what I'm doing is adding in the custom fields into the contact.cs structure

[XmlRpcMember("_Status")]
[Access(Access.Edit | Access.Delete | Access.Add | Access.Read)]
public string _Status { get; set; }

This is a fix but I'd rather not clog up the Contact.cs file with all these extra fields, especially as I'm not able to get into IS to check field types, making this a very labour intensive job (adding field checking it works and changing type if not, for 30+ fields).

simonlongson commented 9 years ago
[XmlRpcMember("_Status")]
[Access(Access.Edit | Access.Delete | Access.Add | Access.Read)]
public dynamic _Status { get; set; }

seems to work so I'll just continue down that route. Hopefully this will help someone else out.

Would still like to know if there's a built in way to read the custom fields though. Cheers

scottcate commented 9 years ago

There are extention methods in the projection for Custom Fields. use IncludeCustomField(string fieldName)

The sample Shows p.Include(c => c.Id)

I think you can add p.IncludeCustomField("status") to the projection, and you'll get that custom field back.

scottcate commented 9 years ago

The Contact Table inherits from an abstract class Table, which has a property of CustomFields, you're value should be in there waiting for you. Is it not?

public IDictionary<string, object> CustomFields
{
    get { return _customFields; }
}
simonlongson commented 9 years ago

Yeah I'm using the following from that sample.

//Find contact vanilla api style
var contacts2 = client.ContactService.FindByEmail(email, new[] {"Id", "Email"});

I'm getting the custom fields back in the xml but I didn't know how to call them in the code. I'm guessing they don't get added to the customFields dictionary unless used the way you've pointed out though. Thank you I'll look into that

scottcate commented 9 years ago

That's right, the CustomFields projection adds them correctly on the return payload, where the string[] ignores the unknown fields. So they're coming back, they just don't have a home.

Enjoy the project!

simonlongson commented 9 years ago

Perfect thank you. Will do. It's been a live saver so far :-)