API breaking change

As a part of the preparation to enrolling new calculation feature, we've made breaking change in the TeamDesk API.

Before, passing NULL as the column value to the Create() function was the sign to API to use default column value.

As now we need to distinguish between column's NULL and column's default, passing NULL now means NULL value, while omiting the column from the XML uses default value.

Following scenario is affected by the change:

/// Get empty DataTable with all columns
DataTable dt = ToDataTable(api.Query("SELECT TOP 0 * FROM [Contacts]"));
DataRow dr = dt.NewRow();
dr["First Name"] = "John";
dr["Last Name"] = "Doe";
dt.Rows.Add(dr);
api.Create("Contacts", FromDataTable(dt));

In old API version the new row will be initialized with default value during the Create() call. In a new version, Create() call will fail with a "Cannot insert empty value into column "Id" message.

To overcome the problem, request the columns you plan to pass the values for. The easiest way to do it is to rewrite the code to get empty data table via Retrieve() call:

string[] columnList = new string[] { "First Name", "Last Name" };
/// Get empty DataTable with selected columns
DataTable dt = ToDataTable(api.Retrieve("Contacts", columnList, new int[] {0});
DataRow dr = dt.NewRow();
dr["First Name"] = "John";
dr["Last Name"] = "Doe";
dt.Rows.Add(dr);
api.Create("Contacts", FromDataTable(dt));

Please update your code.

Tweet about this on TwitterShare on Facebook0Share on Google+0