Monday, December 8, 2014

Get list of Entities in CRM query by Display Name (CRM bulk update)

Hello World,


MetadataSchema.Entity does not have the Display Name of the Entity in it. To get Display Name of a Entity we have to use MetadataSchema.LocalizedLabel
In the bellow query I get the all Entities where Entity Display Name starts from 'Z'.

select distinct e.Name, e.LogicalName, e.OriginalLocalizedName, OptionSetValue.Label
from MetadataSchema.Entity as e inner join
MetadataSchema.LocalizedLabel as OptionSetValue on (e.EntityId = OptionSetValue.ObjectId and
OptionSetValue.ObjectColumnName = 'LocalizedName')
where OptionSetValue.Label like 'Z%'
order by OptionSetValue.Label

With this we can easily get a list of entities and can do other necessary implementations in bulk. 


For example this is a good input to the query in below link,
http://matheeid.blogspot.com/2014/12/bulk-hide-entities-from-advance-find-in.html


Bulk Hide Entities from Advance Find in MS Dynamics CRM


Hello World,

If you are in trouble with unnecessary Entities in your Advance Find (that you created while ago and no longer needed) but you don't want to remove them. And you want to hide them from your customers. And you are too lazy and you want one query that works for all. :)
I was that lazy.

EntityMetadata.IsValidForAdvancedFind Property 

     - Gets or sets whether the entity will be shown in Advanced Find

if IsValidForAdvancedFind = 1 
then referring entity will be shown in Advance Find.


Therefore to hide a entity from Advance Find we can write - 

         update MetadataSchema.Entity
         set IsValidForAdvancedFind = 0
         where  Name = 'EntityName' 

Above will hide the contact  entity for all users  on the advanced.


Then to hide the Entity been displayed under related Entities we can write,

update MetadataSchema.Relationship 
set IsValidForAdvancedFind = 0
where ReferencingEntityId = (select MetadataSchema.Entity.EntityId 
    from MetadataSchema.Entity 
    where Name = 'EntityName') and IsValidForAdvancedFind  = 1)


If you have multiple Entities to update you can easily change the '=' to 'IN' and write all the Entities as a array.

update MetadataSchema.Entity 
set IsValidForAdvancedFind = 0 
where Name IN ('EntityName1', 'EntityName2', ......)


Hope this would be useful
Mathee

Thursday, October 23, 2014


When Run CRM  report if you don't get exact page count as below,


You can changes this by changing CRM  report viewer aspx file.

go to 
CRM/CRMWeb/CRMReports/rsviewer/reportviewer.aspx file

and change the below highlighted report control properties by adding PageCountMode="Actual" property.

In default report viwer pageCountMode is Estimate.


</style>
</head>
<body style="<%if (doNotShowBorder) { %> border-style:none;<% } %>">
<div style="height:100%; width:100%; position:absolute">
<form id="form1" runat="server" style="height:100%">
<asp:ScriptManager id="scriptManager"  runat="server" />
<rsweb:ReportViewer id="reportViewer"  runat="server" width="100%" height="100%"/>
</form>
</div>

</body>
</html>




<rsweb:ReportViewer id="reportViewer" PageCountMode="Actual"   runat="server" width="100%" height="100%"/>

Thursday, June 5, 2014

Zip files in ASP.Net, .net framework 4.0 with Telerik

For .Net Framework 4.0 and bellow there is no inbuilt zipping functionality. 3rd party libraries like DotNetZip, SharpZipLib are playing a great role in this scenario. But if you already use Telerik custom controls for your other developments on a project then you can easily use Telerik ZipPackage to crate zip  files.

using Telerik.Web.Zip;
using System.IO;
.....
...
..
Private void GeneratePdfFiles()
{
...//report parameters and data source credentials

    MemoryStream memoryStream = new MemoryStream();
    ZipPackage Package = ZipPackage.Create(memoryStream);
    Stream stream = default(Stream);

    foreach(reportParameters  in reportParameterCollection)
   {
    byte[] reportByte= RenderReport(reportServerUrl, reportParameters, reportPath, dataSourceCredentials, networkCredential, "pdf");
    stream = new MemoryStream(reportByte);
    Package.AddStream(stream, string.Format("ReportName.pdf"), Telerik.Web.Zip.CompressionType.Default);
    }
SendZipToClient(memoryStream , Package);
}

private void SendZipToClient(MemoryStream memStream, ZipPackage Package)
{  
    Package.Close(false);
    memStream.Position = 0;
    if (memStream != null && memStream.Length > 0)
    {
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment; filename=FormB.zip");
        Response.ContentType = "application/zip";
        Response.BufferOutput = false;   // to prevent buffering
        byte[] buffer = new byte[1024];
        int bytesRead = 0;
                while ((bytesRead = memStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    Response.OutputStream.Write(buffer, 0, bytesRead);
                }
                Response.End();
    }
}