Wednesday, 11 March 2015

Web Resource creation through SDK message

For a web resource creation through SDK, i referred one msdn page click. In this page they read a text file convert them into binary content and then converted into base64 string.

In my case i had HTML on CRM form Fields, so i fetch the field in Plugin and converted its content into binary format and finally into base64 string. the code for which goes as follows

               string JSContent = TileConfiguration.Attributes["livetile_jscontent"].ToString();
                string HTMLContent = TileConfiguration.Attributes["livetile_htmlcontent"].ToString();

                var bytes = Encoding.UTF8.GetBytes(JSContent + HTMLContent);
                var base64 = Convert.ToBase64String(bytes);

                //Set the Web Resource properties
                WebResource wr = new WebResource
                {
                    Content = base64,
                    DisplayName = "Test1",
                    Description ="Sample Test",
                    Name = "livetile_" +"test1",
                    LogicalName = WebResource.EntityLogicalName,

                   //you can specify type for web resource format
                   Webpage (HTML) .htm, .html 1
                    Style Sheet (CSS) .css 2
                    Script (JScript) .js 3
                    Data (XML) .xml 4
                    Image (PNG) .png 5
                    Image (JPG) .jpg 6
                    Image (GIF) .gif 7
                    Silverlight (XAP) .xap 8
                   StyleSheet (XSL) .xsl, .xslt 9
                     Image (ICO) .ico 10

                    WebResourceType = new OptionSetValue(1)
                };

                CreateRequest cr = new CreateRequest
                {
                    Target = wr
                };
                //Set the SolutionUniqueName optional parameter so the Web Resources will be
                // created in the context of a specific solution.
                //cr.Parameters.Add("SolutionUniqueName", _ImportWebResourcesSolutionUniqueName);

                CreateResponse cresp = (CreateResponse)service.Execute(cr);

To update the same web resource, You can do it using UpdateRequest, the code for which goes like below

                WebResource wr = new WebResource
                {
                   //Just pass the web resource ID
                    Id = new Guid(TileConfiguration.Attributes["livetile_webresourceid"].ToString()),
                    Content = base64,
                    DisplayName = "Test1",
                    Description = "Sample Test",
                    Name = "livetile_" + "test1",
                    LogicalName = WebResource.EntityLogicalName,
                    WebResourceType = new OptionSetValue(1)
                };

                UpdateRequest up = new UpdateRequest
                {
                    Target = wr
                };

             
                service.Execute(up);

Thanks.

Sunday, 1 March 2015

Retrieve CRM Entity Attributes List

To retrieve CRM Entity Attributes Listyou will be require to retrieve metadata information through RetrieveAllEntitiesRequest.

After retrieving the metadata, you will get complete list of attributes listed for Entity that you have pass. You can use the following code given below:

            // Retrieve the MetaData.
            RetrieveEntityRequest metaDataRequest = new RetrieveEntityRequest();

            RetrieveEntityResponse metaDataResponse = new RetrieveEntityResponse();

            metaDataRequest.EntityFilters = EntityFilters.Attributes;

            metaDataRequest.LogicalName = LOGICAL NAME;
                                          // your entity logical name goes here like "account"

            metaDataResponse = (RetrieveEntityResponse)service.Execute(metaDataRequest);

            EntityMetadata currentEntity = metaDataResponse.EntityMetadata;

            //AttributeMetadata contains all the metadata for an entity attribute.

            foreach (AttributeMetadata attribute in currentEntity.Attributes)
            {

                var attributeName = attribute.LogicalName;


            }

Thanks.