locked
CrmDateTime with SDK RRS feed

  • Question

  • Hello,

    I created a custom form using CRM webservice.
    I would like to insert a date into CRM. I tried patrimonyAccount.new_vendordate = new CrmDateTime() { Value = Convert.ToDateTime(element.Date).ToString() }; but it didn't work.
    Element.Date got format dd/MM/yyyy.

                foreach (ProductCategory element in selectedElements)
                {
                    new_patrimonyaccount patrimonyAccount = new new_patrimonyaccount();
    
                    patrimonyAccount.new_account = new Lookup { Value = new Guid(RequestParam) };
                    patrimonyAccount.new_accountid = new Lookup { Value = new Guid(RequestParam) };
                    patrimonyAccount.new_category = new Lookup() { Value = new Guid(element.CategoryId) };
                    patrimonyAccount.new_product = new Lookup() { Value = new Guid(element.ProductId) };
                    patrimonyAccount.new_vendor = element.Vendor;
                    patrimonyAccount.new_vendordate = new CrmDateTime() { Value = Convert.ToDateTime(element.Date).ToString() };                    
                        //new CrmDateTime() { time = Convert.ToDateTime(element.Date) };
                    patrimonyAccount.new_comment = element.Comment;
    
                    rollbackList.Add(PatrimonyManagement.CreatePatrimony(patrimonyAccount)); 
                }
    Thank you in advance
    Wednesday, February 15, 2012 11:16 AM

Answers

  • Use sortable date/time pattern for the CrmDateTime.
    patrimonyAccount.new_vendordate = new CrmDateTime() { Value = Convert.ToDateTime(element.Date).ToString("s") };

    Shaurya Anand
    MCPD, MCTS, MCAD, MCP | Data'Flock Consultancy Services | shaurya.anand+mscrmforum@dataflock.com
    Any views or opinions presented in this public post is solely those of mine and do not necessarily represent those of Data'Flock Consultancy Services.

    • Marked as answer by KMAREC Wednesday, February 15, 2012 1:02 PM
    Wednesday, February 15, 2012 12:23 PM