Showing posts with label tool. Show all posts
Showing posts with label tool. Show all posts

Saturday, October 20, 2012

Dynamics CRM 2011 Form Script Analyzer

Dynamics CRM 2011 Form Script Analyzer

Few weeks ago i needed to get all the Javascript that is running in one of our customers Dynamics CRM 2011 Organization, I needed to get out all the Web Resource that are used, where are they used, what are the function that are running and on what are they running on (Onload, OnChange, OnSave, Ribbon buttons).
It was sisyphean work but after going over each Web Resource and their dependencies, I got the list out. This is what made me think, maybe I should build such a tool that takes it all out to an CSV file.

Yesterday, while surfing the web I've found the tool that does excetly that.

In TechEd New Zealand 2012 Gayan Perera presented a talk named:
Advanced Bag of Tips & Tricks for Microsoft Dynamics CRM 2011 Developers

I've enjoyed the presentation very much.
It was about:
T4 Code generation
MSCRM JS
Script#
How to convert managed solution to unmanaged solution
ILMerge
and Form Script Analyzer.

Back to the tool:
The Form Script Analyzer is Console Application tool that exports the Web resources and where their functions are called.

You can download it here : Download
For detailed description go to the TechEd Video and skip to 39 minutes (My recommention is to see the whole thing)

I haven't tried the tool yet, but it seems promising.

Thursday, July 21, 2011

MSCRM 2011 early binding plugin

Checked on MSCRM 2011 on premise and online.

*** I think it's important to understand what is going behind the scenes, here's easier option for creating plugin with early binding. It's done using Dynamics CRM 2011 developer toolkit.
http://dynamicslollipops.blogspot.com/2012/02/mscrm-2011-using-early-binding-in.html

When i've tried to follow the sdk:

"Walkthrough: Build a Plug-in That Connects to Microsoft Dynamics CRM 2011 Using Developer Extensions"
I've ended up looking the web for a way to register plugin which refernced Microsoft.Xrm.Client.dll,
The plugin registration tool kept given me errors because it couldn't find Microsoft.Xrm.Client.dll
Could not load file or assembly 'Microsoft.Xrm.Client, Version=5.0.9688.1154, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

All the solution in the web suggested to use ILMerge for merging the plugin assembly with the 


Microsoft.Xrm.Client.dll and many other not intuitive solutions.
WTF?!?! There most be easier why to enjoy the early binding with out all this mess.

It's possible, just follow these steps:

1) create the xrm class using CrmSvcUtil
Example:
CrmSvcUtil.exe /out:Xrm.cs /url:http://crm2011:5555/Basic/XRMServices/2011/Organization.svc /username:yyyyy /password:xxxxx /namespace:Xrm/serviceContextName:XrmServiceContext 
2) Add the created file to the project
3) Add reference to the project
microsoft.xrm.sdk.dll
microsoft.crm.sdk.proxy.dll
4) inherit IPlugin

This is it.

this is how you get the context:
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory =
                    (IOrganizationServiceFactory)serviceProvider.GetService(
                typeof(IOrganizationServiceFactory));
                IOrganizationService service =
                serviceFactory.CreateOrganizationService(context.UserId);

                XrmServiceContext xrm = new XrmServiceContext(service);
Example for the plugin:
public class SLAPlugin : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
            Entity entity;
            // Check if the input parameters property bag contains a target
            // of the create operation and that target is of type Entity.
            if (context.InputParameters.Contains("Target") &&
            context.InputParameters["Target"] is Entity)
            {
                // Obtain the target business entity from the input parameters.
                entity = (Entity)context.InputParameters["Target"];

                // Verify that the entity represents a contact.
                if (entity.LogicalName != Incident.EntityLogicalName) { return; }
            }
            else
            {
                return;
            }

            try
            {
                IOrganizationServiceFactory serviceFactory =
                    (IOrganizationServiceFactory)serviceProvider.GetService(
                typeof(IOrganizationServiceFactory));
                IOrganizationService service =
                serviceFactory.CreateOrganizationService(context.UserId);

                XrmServiceContext xrm = new XrmServiceContext(service);
                
                // Extract the tracing service.
                ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                if (tracingService == null){
                    throw new InvalidPluginExecutionException("Failed to retrieve the tracing service.");
                }

                if(!context.PostEntityImages.Contains("MyImage")){
                    throw new InvalidPluginExecutionException("Failed to retrieve the Post Image.");
                }

                Entity postEntity = context.PostEntityImages["MyImage"];
                Incident caseTemp = postEntity.ToEntity<Incident>();

                if (caseTemp != null)
                {
                    //only if missing active conditionset start looking for one
                    if (caseTemp.new_ActiveCoditionSetId == null)
                    {
                        tracingService.Trace("Start looking for conditionset");
                        MSCRM2011SLAProcessWorker a = new MSCRM2011SLAProcessWorker();
                        a.GetConditionSetAndUpdateCase(xrm, tracingService,caseTemp);
                    }
                }
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException(
                "An error occurred in the plug-in.", ex);
            }
        }
    }
Updating newly created entity that is not in the context
//create update case
Incident caseToUpdate = new Incident
{
 IncidentId = activeCase.IncidentId
};
//update the update case
xrm.Attach(caseToUpdate);
xrm.UpdateObject(caseToUpdate);
xrm.SaveChanges();
    
Hope it helps...

Sunday, July 17, 2011

Export Import user saved views Microsoft Dynamics Crm 2011

Export Import user saved views Microsoft Dynamics Crm 2011.
Because user can't "move" his saved views from one environment to another, I've create Silverlight application that does it.

The application can be downloaded from here:
http://exportimportuserview.codeplex.com/releases

Prerequisites:
     1) The "SLExportImportUserViews" solution installed on both environments.

Instructions:
     1) Go to the first environment.
     2) Open the HTML Web resource and preview the page.
     3) Export your saved views to xml file.
     4) Go to the other environment.
     5) Open the Silverlight application.
     6) Open the HTML Web Resource and preview the page.
     7) Go to the Import Tab.
     8) Click on ImportXML.
     9) Choose the xml file.
    10)  Click on Import all to crm.

Draw backs:
    1) Because it's odate I can't retrieve other users saved views and I can't assign the saved views to another user from the Silverlight application.
        *Can be fixed by using the wcf service instaed of the Odata or after importing the views assign them from the advanced find window
    2) All the saved views in the grid Exported to the xml file.
    3) All the saved views in the grid Imported to the CRM.
        *Can easily be fixed by exporting and importing only selected items.

The application can be downloaded from here:
http://exportimportuserview.codeplex.com/releases

Thursday, June 30, 2011

Sending report as pdf in email

Microsoft dynamics crm 2011 on premise only solution. (It's not possible to get to the reporting services web services in the online environment).
1) Get the report from the ssrs web service in pdf format
2) Create email from email template
3) Create the attachment
4) Send the email

I had to do it generic enough that the customer could do it with any report he would like. so I've exported some of the guidelines to xml file, created console application which can be run with windows task scheduler.
It can be found here:
http://emailreport.codeplex.com/

Download link:
http://emailreport.codeplex.com/releases/view/69298

Another option is using the ssrs.
Setup reporting service SMTP and try this solution:
http://community.dynamics.com/product/crm/crmtechnical/b/crmpowerobjects/archive/2011/06/29/report-scheduling-and-email-subscription-in-crm-2011.aspx