Showing posts with label Web resources. Show all posts
Showing posts with label Web resources. Show all posts

Thursday, March 5, 2015

MS CRM 2011 KB Article customization Issue.

Recently I have encountered some issue while customizing Kb Article Entity. I was doing following configuration in Article form.

1. Add Base Templet lookup to the form
2. Add status picklist to the form

What I notice while adding above fields to the form was that these fields became required and locked on the form.
Then what happened was, while creating new Article my ribbon was not loading.
We have tried to debug the JS and found that it’s breaking in below highlighted point. So I knew that something is wrong with the Base Template field which I added earlier.
n addition to that we have noticed that Submit, Approve,.. buttons were disabled on the form.
But it’s enabled in the main grid.
We knew that something was wrong with the fields we added to the Form, but now we cannot remove these two fields from the form as it became locked in the form, we consult Microsoft on this as it seems to be a product bug.

Then the Microsoft advise us to remove it manually form the customization xml. We followed the below steps then everything seems to be fine.

 • Create a New Solutions with Kb Article entity
 • Export the solutions as a unmanage and open customisation.xml
 • Edited the customization.xml and commented the control for kbarticletemplateid and statecode.
 • Saved the customization.xml file and zipped the solution.
 • Imported the solution back to the system.
 • Published the customization and issue was resolved by that.

Tuesday, August 13, 2013

CRM 2011: How to read Web resource from code

Following code snippet will help you to read content of the web resource.
/// 
/// Reads the CRM Web Resource by its unique name as a string
/// 

        public string ReadContent(string resourceName)
        {
            byte[] byteArray = ReadBytes(resourceName);
            if (byteArray != null)
            {
                return System.Text.Encoding.UTF8.GetString(byteArray);
            }
            
            return string.Empty;            
        }

/// 
/// Reads the CRM Web Resource by its unique name as a byte array
///         
        public byte[] ReadBytes(string resourceName)
        {
            try
            {
                WebResource webResource = new WebResource();

                QueryExpression query = new QueryExpression()
                {
                    EntityName = "webresource",
                    ColumnSet = new ColumnSet("content"),
                    Criteria = new FilterExpression
                    {
                        FilterOperator = LogicalOperator.And,
                        Conditions = 
                        {
                            new ConditionExpression{AttributeName = "name", Operator = ConditionOperator.Equal, Values = { resourceName }}
                        }
                    }
                };

                RetrieveMultipleRequest retrieveMultipleRequest = new RetrieveMultipleRequest { Query = query };

                RetrieveMultipleResponse retrieveMultipleResponse = (RetrieveMultipleResponse)service.Execute(retrieveMultipleRequest);

                if (retrieveMultipleResponse != null && retrieveMultipleResponse.EntityCollection != null && retrieveMultipleResponse.EntityCollection.Entities.Count > 0)
                {
                    webResource = (WebResource)retrieveMultipleResponse.EntityCollection.Entities[0];

                    byte[] byteArray = Convert.FromBase64String(webResource.Content);

                    return byteArray;
                }

            }
            catch (Exception exception)
            {
                
            }

            return null;
        }

MS CRM 2011 KB Article customization Issue.

Recently I have encountered some issue while customizing Kb Article Entity. I was doing following configuration in Article form. 1. Add Ba...