Post

1 follower Follow
0
Avatar

.Net Item Update

I have tried the API example for updating an item to no avail! Does someone have an example that works that they can share? Here's a code snippet of what I currently have in place to acquire the item of interest (I pass in valid parameters so they aren't the issue here):

public Boolean ProcessItem(string itemAction, int appId, Item itemCurrentObject, Client client)
{
// Setup a new item instance - this is also currently needed when you update an item
var item = new Item();

        // unmapped values
        string fldProjectName = "Podio-Issuetrak Integration Test III";
        string fldDescription = "This is a test from Lyle";
        string fldHealth = "1";
        string fldOwner = "Lyle";
        int fldEstimatedHours = 10;

        foreach (ItemField fld in itemCurrentObject.Fields)
        {
            switch (fld.Type)
            {
                case "text":      // Text field
                                    var textField = item.Field<TextItemField>(fld.ExternalId);
                                    textField.ExternalId = fld.ExternalId; // Don't forget this
                                    textField.Value = fldProjectName;
                                    item.Fields.Add(textField); // Don't forget this
                                    break;

                case "category":    // Category field - the Question field works the same way
                                    var categoryItemField = item.Field<CategoryItemField>(fld.ExternalId);
                                    categoryItemField.ExternalId = fld.ExternalId;
                                    //categoryItemField.OptionIds = [1]; //[1, 2, 3]; // If multiple are allowed
                                    categoryItemField.OptionId = 1; // If only one is allowed
                                    if (fld.ExternalId == "Status")
                                    {
                                        categoryItemField.OptionId = 2; // If only one is allowed
                                    }
                                    item.Fields.Add(categoryItemField);
                                    break;

                case "app":         // App reference field
                                    var appRefField = item.Field<AppItemField>(fld.ExternalId);
                                    appRefField.ExternalId = fld.ExternalId;
                                    //appRefField.ItemIds = [123, 456]; // Ids of items this app is allowed to reference
                                    item.Fields.Add(appRefField);
                                    break;

                case "contact":     // Contact field
                                    var contactField = item.Field<ContactItemField>(fld.ExternalId);
                                    contactField.ExternalId = fld.ExternalId;
                                    //contactField.ContactIds = new List<int> { 123 }; // Profile ids of users and/or contacts
                                    item.Fields.Add(contactField);
                                    break;

                case "location":    // Location field
                                    var locationField = item.Field<LocationItemField>(fld.ExternalId);
                                    locationField.ExternalId = fld.ExternalId;
                                    //locationField.Locations = new List<string>() { "Some road 345, Somewhere" }; // Addresses are just strings
                                    item.Fields.Add(locationField);
                                    break;

                case "duration":    // Duration field
                                    var durationField = item.Field<DurationItemField>(fld.ExternalId);
                                    durationField.ExternalId = fld.ExternalId;
                                    //durationField.Value = TimeSpan.FromSeconds(3600); // Any timespan will work
                                    item.Fields.Add(durationField);
                                    break;

                case "progress":    // Progress field
                                    var progressField = item.Field<ProgressItemField>(fld.ExternalId);
                                    progressField.ExternalId = fld.ExternalId;
                                    progressField.Value = 55; // A number between 0 and 100
                                    item.Fields.Add(progressField);
                                    break;

                case "money":       // Money Field
                                    var moneyField = item.Field<MoneyItemField>(fld.ExternalId);
                                    moneyField.ExternalId = fld.ExternalId;
                                    moneyField.Value = (decimal)123.45; // A decimal number
                                    moneyField.Currency = "USD"; // One the currencies allowed for this field
                                    item.Fields.Add(moneyField);
                                    break;

                case "date":        // Date field
                                    var dateField = item.Field<DateItemField>(fld.ExternalId);
                                    dateField.ExternalId = fld.ExternalId;
                                    dateField.Start = DateTime.Now;
                                    dateField.End = DateTime.Now.AddHours(3);
                                    item.Fields.Add(dateField);
                                    break;

                default:
                                    Console.WriteLine("Default Case");
                                    break;
            }
            Console.WriteLine(fld.Label);
        }

if(itemAction == "New") {
// Create as a new item
int lclAppId = 88888;
client.ItemService.AddNewItem(lclAppId, item);
} else {
// - or update an existing item by setting the ItemId
item.ItemId = itemCurrentObject.ItemId;
client.ItemService.UpdateItem(item);
}

-- End of code snippet

I am at a loss as to why there is no errors but when I refresh Podio Projects List, it hasn't updated any of the field values for the specific item. Any ideas?

Lyle Bruney

Please sign in to leave a comment.