locked
CRM 4.0 Merge Account issue for Read Only Fields RRS feed

  • Question

  • Respected Community Members,

                   We are trying to figure out whether CRM 4.0 Merge Account operation has any switch to respect the readonly field or not. What I mean is when we merge 2 accounts, even some fields are read only in the form, the Merge window will allow almost any fields to merge. Making this verification in Plugin code for read only might be too much. Does this a bur in CRM 4.0 or what??

    Any idea whether is there any settings we have to enable for that or what? Please assist.

    Thanks,

    Nick

    Wednesday, December 11, 2013 2:34 PM

Answers

  • I resolved my issue by using above article which pretty much gives us access to all readonly field within CRM Form. Only fields that I disable in java script are the one needs to be manually checked.Below is the sample code if any one needs this.

    private static void FilterReadOnlyAttributes(IPluginExecutionContext context, DynamicEntity entityToLookUp, string strMasterAccountNumber)
            {
                using (var crmService = context.CreateCrmService(true))
                {
                    
                    var formXmlRequest = new RetrieveFormXmlRequest { EntityName = entityToLookUp.Name };
                    var formXmlResponse = (RetrieveFormXmlResponse)crmService.Execute(formXmlRequest);
                    var formXml = formXmlResponse.FormXml;               
    
                    var formXmlDocument = new XmlDocument();
                    formXmlDocument.LoadXml(formXml);
                    var disabledAttributes = formXmlDocument.SelectNodes("//control[@disabled='true']/@id");
    
                    foreach (XmlNode disabledAttribute in disabledAttributes)
                    {
    
                        if (entityToLookUp.Properties.Contains(disabledAttribute.Value))
                        {
                            throw new InvalidPluginExecutionException(disabledAttribute.Value + " field is ReadOnly. Please do not select Any ReadOnly fields while Merge.");
                        }
                    }
    
                   
                        List<string> strAttributesList = new List<string>();
                        strAttributesList.Add("name");
                        
                        foreach (string strAttribute in strAttributesList)
                        {
                            if (entityToLookUp.Properties.Contains(strAttribute))
                            {
                                throw new InvalidPluginExecutionException(strAttribute + " field is ReadOnly. Please do not select any ReadOnly fields while Merge.");
    
                            }
                        }
                   }
            }

    Thanks,

    Nick


    • Edited by Nicksoft2011 Thursday, December 12, 2013 9:32 PM
    • Marked as answer by Nicksoft2011 Thursday, December 12, 2013 9:33 PM
    Thursday, December 12, 2013 9:32 PM

All replies

  • so far I got one article it says, it is Bug in CRM 4.0. But not for sure .

    http://thecrmgrid.wordpress.com/2011/01/26/disabled-fields-incorrectly-saving-to-the-crm-database/

    Any one can please point me to right direction to find out the ReadOnly field from Plugin stage 10??

    Thanks,

    Nick

    Wednesday, December 11, 2013 8:15 PM
  • I resolved my issue by using above article which pretty much gives us access to all readonly field within CRM Form. Only fields that I disable in java script are the one needs to be manually checked.Below is the sample code if any one needs this.

    private static void FilterReadOnlyAttributes(IPluginExecutionContext context, DynamicEntity entityToLookUp, string strMasterAccountNumber)
            {
                using (var crmService = context.CreateCrmService(true))
                {
                    
                    var formXmlRequest = new RetrieveFormXmlRequest { EntityName = entityToLookUp.Name };
                    var formXmlResponse = (RetrieveFormXmlResponse)crmService.Execute(formXmlRequest);
                    var formXml = formXmlResponse.FormXml;               
    
                    var formXmlDocument = new XmlDocument();
                    formXmlDocument.LoadXml(formXml);
                    var disabledAttributes = formXmlDocument.SelectNodes("//control[@disabled='true']/@id");
    
                    foreach (XmlNode disabledAttribute in disabledAttributes)
                    {
    
                        if (entityToLookUp.Properties.Contains(disabledAttribute.Value))
                        {
                            throw new InvalidPluginExecutionException(disabledAttribute.Value + " field is ReadOnly. Please do not select Any ReadOnly fields while Merge.");
                        }
                    }
    
                   
                        List<string> strAttributesList = new List<string>();
                        strAttributesList.Add("name");
                        
                        foreach (string strAttribute in strAttributesList)
                        {
                            if (entityToLookUp.Properties.Contains(strAttribute))
                            {
                                throw new InvalidPluginExecutionException(strAttribute + " field is ReadOnly. Please do not select any ReadOnly fields while Merge.");
    
                            }
                        }
                   }
            }

    Thanks,

    Nick


    • Edited by Nicksoft2011 Thursday, December 12, 2013 9:32 PM
    • Marked as answer by Nicksoft2011 Thursday, December 12, 2013 9:33 PM
    Thursday, December 12, 2013 9:32 PM