Skip to content
Dan Lively edited this page Nov 8, 2013 · 4 revisions

The SugarSharp library contains several useful extension methods for formatting data for the SugarCRM API.

##DateTime Formatting

  • ToSugarDateString() -- converts to date string
  • ToSugarDateTimeString() -- converts datetime to UTC and formats to proper string
DateTime now = DateTime.Now;
            
string recordID = "";

try
{
    recordID = sugar.Create("Accounts", new
    {
     name = "McTest Industries",
     description = "this is a test message",
     test_date_c = now.ToSugarDateString(), //converts to proper date format
     datetime_test_c = now.ToSugarDateTimeString() //converts to UTC datetime format
    });

}
catch (SugarException e)
{
    Console.WriteLine(e.Message.ToString());
}

##Multi-Select Formatting

This extension methods converts a List into a proper formatted multi-select string to be inserted through the API.

var values = new List<string>(){"a","b","c"};
values.ToSugarMultiSelect();
//returns "^a^,^b^,^c^";
Clone this wiki locally