locked
Adding a custom bit attribute to a crm entity RRS feed

  • Question

  • I have a bunch of custom attributes in the account dynamic entity which are initialy NULL. Before setting their value on those properties of type 'StringPorerties' I add them to the entity using following code:
    -------------- code start -------------------
    Dim myProperty As New StringProperty
    myProperty.Name = "somename"
    myProperty.Value =
    "somevalue"
    entity.Properties.Add(myProperty)
    --------- code end ---------------
    Code works fine and database is updated with correct value. However, for properties of type 'bit' I am using following code:
    --------- code start --------------
    Dim myProperty As New CrmBooleanProperty()
    myProperty.Name = prop
    myProperty.Value =
    New CrmBoolean()
    myProperty.Value.Value =
    False
    entity.Properties.Add(myProperty)
    --------- code end ---------------
    When I update the Dynamic target, I get the following error:

    There was an error generating the XML document.

    I suspect this is not how a 'bit' attribute should be added to a dynamic entity. Can anyone advice how can this be done?

    Monday, August 9, 2010 2:50 PM

Answers

  • See the SoapException -> Details -> InnerXml or InnerText property of the exception. You will get more details in it.

    Just go to Event Viewer on CRM app server and check for errors in Application Event Log.

    Use Diagnostic tool for error description
    http://blogs.msdn.com/benlec/archive/2008/03/04/crmdiagtool4-for-microsoft-crm-4-0-has-been-released.aspx

     

    You can use the below method to set Boolean field:

    public static CrmBooleanProperty GetCrmBooleanProperty(string fieldName, bool fieldValue)
            {
                CrmBooleanProperty prop = new CrmBooleanProperty();
                prop.Name = fieldName;
                prop.Value = new CrmBoolean();
                prop.Value.Value = fieldValue;

                return prop;
            }


    Hope this helps.


    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant

    Yeah. This must work.

    or

    try another way:

                CrmBooleanProperty myProperty= new CrmBooleanProperty();
                myProperty.Name = prop;
                CrmBoolean boolValue= new CrmBoolean();
                boolValue.Value = false;

                myProperty.Value=boolValue;

     

    I doubt you are trying to set value for attribute which is not of "bit" type [Sorry, if I am wrong]

    Thank you.

    JayshriP

    Friday, August 13, 2010 11:40 AM

All replies

  • Please check are you using correct field name

    myProperty.Name = prop

    Also this should be

    myProperty.Name = "prop"


    Mahain : http://mahenderpal.wordpress.com
    Monday, August 9, 2010 2:56 PM
    Moderator
  • prop is merely a string variable with the name of the property (ie. prop="somename"). Question is: is this is the right way to add an attribute of type 'bit' to a dynamic entity? Isn't there a 'bitProperty' object just like the 'StringProperty' object? If this is the right way, how do I debug the error? If it is not, what is the right way?
    Monday, August 9, 2010 3:06 PM
  • Your code seems correct. You do use the CrmBooleanProperty which is fine.

    If I was you, I will take a crm trace using CrmDiagTool. In the trace, you will have the xml string that represents the DynamicEntity and will be able to see what is going wrong...

     


    My blog : http://mscrmtools.blogspot.com

    All my tools on my new dedicated site: MSCRMTools Repository
    Monday, August 9, 2010 3:09 PM
    Moderator
  • The code for CrmBooleanProperty looks fine, is the attribute published, and spelt correctly?

    Monday, August 9, 2010 3:15 PM
  • Ok,

    Other then that you code seems ok, try to catch SoapException and check for detail error


    Mahain : http://mahenderpal.wordpress.com
    Monday, August 9, 2010 3:18 PM
    Moderator
  • I did take a crm trace but looking at the logs I am not sure how to tell what's wrong? Any advice?
    Monday, August 9, 2010 3:43 PM
  • That''s the thing, the error is not trappe din hte SoapException but rather in the Exception block. Is there any other way to find out more about the error?
    Monday, August 9, 2010 3:45 PM
  • See the SoapException -> Details -> InnerXml or InnerText property of the exception. You will get more details in it.

    Just go to Event Viewer on CRM app server and check for errors in Application Event Log.

    Use Diagnostic tool for error description
    http://blogs.msdn.com/benlec/archive/2008/03/04/crmdiagtool4-for-microsoft-crm-4-0-has-been-released.aspx

     

    You can use the below method to set Boolean field:

    public static CrmBooleanProperty GetCrmBooleanProperty(string fieldName, bool fieldValue)
            {
                CrmBooleanProperty prop = new CrmBooleanProperty();
                prop.Name = fieldName;
                prop.Value = new CrmBoolean();
                prop.Value.Value = fieldValue;

                return prop;
            }


    Hope this helps.


    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant
    • Proposed as answer by Ranjitsingh R Monday, August 9, 2010 3:57 PM
    Monday, August 9, 2010 3:52 PM
  • Hi Ranjitsingh, Once I setup the new attribute, I set the value to a true or false. The innerexception tells me that the boolean value is not supported. I tried setting the value to 0 or 1. I got the message the int32 value is not supported. I am back to my original question: Is this the correct way to add a bit attribute? If so, how do I set the value if neither boolean nor integer are supported?
    Monday, August 9, 2010 5:13 PM
  • Were you able to resolve this issue?  If not, anyone have some additional advice for this poster? 

    Regards, Donna

    Thursday, August 12, 2010 2:38 PM
  • See the SoapException -> Details -> InnerXml or InnerText property of the exception. You will get more details in it.

    Just go to Event Viewer on CRM app server and check for errors in Application Event Log.

    Use Diagnostic tool for error description
    http://blogs.msdn.com/benlec/archive/2008/03/04/crmdiagtool4-for-microsoft-crm-4-0-has-been-released.aspx

     

    You can use the below method to set Boolean field:

    public static CrmBooleanProperty GetCrmBooleanProperty(string fieldName, bool fieldValue)
            {
                CrmBooleanProperty prop = new CrmBooleanProperty();
                prop.Name = fieldName;
                prop.Value = new CrmBoolean();
                prop.Value.Value = fieldValue;

                return prop;
            }


    Hope this helps.


    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant

    Yeah. This must work.

    or

    try another way:

                CrmBooleanProperty myProperty= new CrmBooleanProperty();
                myProperty.Name = prop;
                CrmBoolean boolValue= new CrmBoolean();
                boolValue.Value = false;

                myProperty.Value=boolValue;

     

    I doubt you are trying to set value for attribute which is not of "bit" type [Sorry, if I am wrong]

    Thank you.

    JayshriP

    Friday, August 13, 2010 11:40 AM