locked
Casting of CRM Data Type RRS feed

  • Question

  • Hi,

    Ms Dynamics crm 4.0 How can I set Date Value for the Attribute of Type CrmBooleane when only Boolean is given in String?

    For assiging the CrmBoolean Type Value from the String, I am using following

    DynamicEntity dynProfileObject = new DynamicEntity();

    dynProfileObject.Properties.Add(new CrmBooleanProperty("boolAttributeLogicalName", new CrmBoolean(Convert.ToBoolean(boolVariable))));

    Similarly, can anyone help me on the following Crm Data Types

    owner
    status

    Thanks,

    Rajeev.

    Tuesday, February 14, 2012 6:30 AM

Answers

All replies

  • Hi Rajeev,

    We cannot use other datatypes for setting the boolean type attribute value.

    In your case if you are looking for a specific date and based on that you need to set true or false in the boolean attribute then use one if statement above that boolean setting. Then your resultant code will be look like this.

    if(yourDateValue == DATEtoCHECK)

      {  

     dynProfileObject.Properties.Add(new CrmBooleanProperty("boolAttributeLogicalName", new CrmBoolean(true)));

       }
    else
       {

     dynProfileObject.Properties.Add(new CrmBooleanProperty("boolAttributeLogicalName", new CrmBoolean(false)));

       }

    Thanks and Regards

    Ramu

    Tuesday, February 14, 2012 6:46 AM
  • Hello Raveej,

    As for me you don't need any casts because boolean type contains only 2 possible values - True and False so it is possible to use following code:

    DynamicEntity dynProfileObject = new DynamicEntity();
    
    if (boolVariable == "true")
    dynProfileObject["boolAttributeLogicalName"] = new CrmBoolean(true);
    else
    dynProfileObject["boolAttributeLogicalName"] = new CrmBoolean(false);
    


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    Tuesday, February 14, 2012 10:31 AM
    Moderator
  • Similarly, can anyone help me on the following Crm Data Types

    owner
    status

    Thanks,

    Rajeev.

    Tuesday, February 14, 2012 10:51 AM
  • Hi Rajeev,

    Please see the code related to owner in the following URL.

    http://msdn.microsoft.com/en-us/library/bb928422.aspx

    For setting Status we need to use 'SetStateDynamicEntityRequest' class. Here is an example for that.

    http://blogs.msdn.com/b/jonasd/archive/2007/04/04/setting-status-with-setstatedynamicentityrequest.aspx

    Thanks and Regards

    Ramu

    • Proposed as answer by Janu_m Wednesday, February 15, 2012 4:45 AM
    • Marked as answer by CRM Rajeev Tuesday, February 21, 2012 2:02 PM
    Wednesday, February 15, 2012 4:45 AM