locked
CRM 4.0 problem: unable to retrieve CrmDateTime from Post Entity Image RRS feed

  • Question

  • I am hitting a wall on this since the morning today. Please help!!

    this is a post update plugin on a custom entity "new_softwarelicense" and the filtering attribute for the plugin is set to a field "new_terminationdate". I have registered a Post Image on the same attribute. I am triggering the plugin by updating the attribute on the GUI. I am unable to get the value of the new_terminationdate, all the plugin prints to the log file is: "Term Date is --"

    here is the code:

           public void Execute(IPluginExecutionContext context)
            {

                    if (context.PostEntityImages.Properties.Contains("new_softwarelicense") == false)
                        return;
                    DynamicEntity PostSLEntity = (DynamicEntity)context.PostEntityImages["new_softwarelicense"];

                    if (PostSLEntity.Properties.Contains("new_originationdate"))
                    {
                        CrmDateTime terminationDate = (CrmDateTime)PostSLEntity.Properties["new_originationdate"];
                        CrmHelper.Log("Term Date is -" + terminationDate.date + "-");

                    }

            }

    Interestingly, if I try this on a nvarchar attribute, it works fine. not sure what the problem is with CrmDateTime fields. Please help!!

    Thursday, September 22, 2011 4:00 AM

Answers

  • Hi,

    try as follows:

    DateTime terminationDate = ((CrmDateTime)PostSLEntity.Properties["new_originationdate"]).UserTime;

    Or 

     CrmDateTime dtValue = PostSLEntity.Properties["new_originationdate"] as CrmDateTime;

      if (!dtValue.IsNull)

               DateTime terminationDate = dtValue.UserTime;

     


    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Thomas Thankachan Thursday, September 22, 2011 5:42 AM
    • Marked as answer by .NETArch2010 Thursday, September 22, 2011 2:45 PM
    Thursday, September 22, 2011 5:42 AM

All replies

  • Hi,

    try as follows:

    DateTime terminationDate = ((CrmDateTime)PostSLEntity.Properties["new_originationdate"]).UserTime;

    Or 

     CrmDateTime dtValue = PostSLEntity.Properties["new_originationdate"] as CrmDateTime;

      if (!dtValue.IsNull)

               DateTime terminationDate = dtValue.UserTime;

     


    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Thomas Thankachan Thursday, September 22, 2011 5:42 AM
    • Marked as answer by .NETArch2010 Thursday, September 22, 2011 2:45 PM
    Thursday, September 22, 2011 5:42 AM
  • Have you tried terminationDate.Value?
    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav
    Thursday, September 22, 2011 1:52 PM
  • thanks Thomas,

    your first suggetion worked. Basically the date property of CrmDateTime object was blank and not getting populated for reasons unknown. Converting CrmDateTime to DateTime resolved the issue. thanks!

    Blake, didnt get a chance to test your solution, will let you know. thanks,

    Thursday, September 22, 2011 2:45 PM