Random Musings

July 24, 2009

Is it possible to register different event handlers in only one assembly to be registered in Dynamics CRM Plugin ?

Filed under: Dynamics CRM — haditeo @ 9:41 am
Tags:

The answer is Yes.

plugin_registration_tool_main_window

The reason why i need this, is because i would like to register only a single DLL for the Plugin DLL, let’s called it XXX.CRM.Plugin

visual_studio_solution

To register multiple event handler, create multiple classes that implements Execute method of the IPlugin interface, then automatically when you register the plugin, you can load those classes

register_assembly

Now, the question is how do i select which class to be loaded against my event message ? When you register a new step, there is a plugin dropdownlist, you can select which class to be executed. Since we are registering two classes, then there will be two plugin options in the drop down list

select_which_plugin_to_be_executed

Advertisements

July 11, 2009

SketchFlow RC is released

Filed under: sketchflow — haditeo @ 5:11 pm
Tags: ,

I have just read the news that Silverlight 3 is released. But the one that got me interested is Sketch Flow Released Candidate

And then i googled around and find out this screencast and immediately i am interested in it.

I am thinking of creating prototype when customizing Dynamics CRM ASP.NET Web Application, by taking the screenshot of the Dynamics CRM UI as the background and create interactions inside it. Let’s say what happen when you click “Convert to Lead” button or what happen when this data is submitted etc . Users can obtain quick feedback regarding the interaction.

July 8, 2009

BluePrint, YAML and 960 GridSystem

Filed under: css — haditeo @ 3:47 pm
Tags:

First of all, you might ask me ? What are those ?

Blueprint is a CSS framework, which aims to cut down on your development time. It gives you a solid foundation to build your project on top of, with an easy-to-use grid, sensible typography, useful plugins, and even a stylesheet for printing.

and

YAML “Yet Another Multicolumn Layout” (YAML) is an (X)HTML/CSS framework for creating modern and flexible floated layouts. The structure is extremely versatile in its programming and absolutely accessible for end users.

and

The960 Grid System is an effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem.

3 years ago, i have learned CSS extensively to promote table-less design by using CSS. The painful of manual learning is i need to carefully calculate each of the div boxes, reset the position, calculate the boxes width etc. Not to mention that there is browser quirks means that the layout seen in the IE might be not the same if it’s seen on FireFox.

While i browsed around JQuery most popular plugin list, JQuery UI Layout is on the top of the list.

and then i browsed around my favorite website Stack Overflow, and i found some suggestion that there are some CSS framework. That’s when i found these CSS frameworks. Really fabolous, by looking at the demo or sample page. It’s definitely reduce countless hours of calculating and trying to match the design by using div’s.

This article is definitely a must to read to compare each of the css grid framework.

Since my next task was to layout my .ASPX page according to the Dynamics CRM Forms, i will try Blueprint to design the data entry form layout.

July 6, 2009

Create simple domain generator by reading from CRM Metadata

Filed under: c#,Dynamics CRM — haditeo @ 9:30 pm
Tags: ,

Objective
I would like to create my own domain (class) from the custom CRM entity. The advantage of this is to simplify domain persistence and retrieval between application layer and database layer (CRM Web Service)

How to achieve this ?

  • First of all we utilize RetrieveEntityRequest message to retrieve all attributes of the specific entity.
                    RetrieveEntityRequest request = new RetrieveEntityRequest();
                    request.LogicalName = entityName;
                    request.EntityItems = EntityItems.IncludeAttributes;
    
                    RetrieveEntityResponse response = (RetrieveEntityResponse)metadataService.Execute(request);
    
                    EntityMetadata entityMetadata = response.EntityMetadata;
    
                    foreach (AttributeMetadata attributeMetadata in entityMetadata.Attributes)
                    {
                        //loop through all attributes here.
                    }
    
  • There are some interesting attributes of the AttributeMetadata. Such as LogicalName attribute, DisplayName attribute and AttributeType attribute
  • By looping through each of the attributes, i read the relevant template file consisting of the code templates and replace the necessary placeholder with the actual values

    private LookupProperty _#internalVariableName#;
    [CrmAttributeMapping("#crmAttributeMapping#")]
    public LookupProperty #publicPropertyName#
    {
        get { return _#internalVariableName#; }
        set { _#internalVariableName# = value; }
    }
    
    public void Set#publicPropertyName#(Guid value)
    {
        _#internalVariableName# = new LookupProperty("#crmAttributeMapping#", new Lookup("#lookupAttributeMapping#", value));
    }
    
    public bool Is#publicPropertyName#Null()
    {
        if (_#internalVariableName# == null)
            return true;
    
        if (_#internalVariableName#.Value == null)
            return true;
    
        if (_#internalVariableName#.Value.Value == Guid.Empty)
            return true;
            
        return false;
    }
    

    Here are the result of the placeholder value replacement

    private LookupProperty _owninguser;
    [CrmAttributeMapping("owninguser")]
    public LookupProperty owninguser
    {
        get { return _owninguser; }
        set { _owninguser = value; }
    }
    
    public void Setowninguser(Guid value)
    {
        _owninguser = new LookupProperty("owninguser", new Lookup("#lookupAttributeMapping#", value));
    }
    
    public bool IsowninguserNull()
    {
        if (_owninguser == null)
            return true;
    
        if (_owninguser.Value == null)
            return true;
    
        if (_owninguser.Value.Value == Guid.Empty)
            return true;
            
        return false;
    }
    
  • Some clean up needs to be performed to tidy up the public Property name, but this code generator has helped me tremendeously to eliminate boring and repititive tasks of creating custom domain objects by hand.

July 4, 2009

Json.NET and json.js

Filed under: c# — haditeo @ 11:45 am
Tags: ,

Let’s say i have an “Argument” class and “Customer” class below :

    public class Argument
    {
        private string _filterComboType;

        public string FilterComboType
        {
            get { return _filterComboType; }
            set { _filterComboType = value; }
        }

        private string _selectedNameClientId;
        
        public string SelectedNameClientId
        {
            get {return _selectedNameClientId;}
            set {_selectedNameClientId = value;}
        }

        private List<Customer> customerList;

        public List<Customer> Customer
        {
            get { return customerList; }
            set { customerList = value; }
        }
        
        public Argument()
        {
        
        }
    }
    public class Customer
    {
        private string _customerType;
        private string _customerText;
        private string _customerValue;

        public string ObjectType
        {
            get { return _customerType; }
            set { _customerType = value; }
        }

        public string CustomerText
        {
            get { return _customerText; }
            set { _customerText = value; }
        }

        public string CustomerValue
        {
            get { return _customerValue; }
            set { _customerValue = value; }
        }

        public Customer(string strCustomerType, string strCustomerText, string strCustomerValue)
        {
            _customerType = strCustomerType;
            _customerText = strCustomerText;
            _customerValue = strCustomerValue;
        }
        
        public Customer()
        {
        
        }
    }

The purpose of these objects is to be passed along from the “main” page to the “lookup” page to be processed further.

Refer to the sample result of these objects on the JSON string format for one Customer

{"FilterComboType":"NameOfClient","SelectedNameClientId":null,"Customer":[{"ObjectType":"account","CustomerText":"Account E","CustomerValue":"c0b377cf-1766-de11-8f5c-0003ffb4d763"}]}

and here is the sample JSON string result for multiple Customers

{"FilterComboType":"ContactList","SelectedNameClientId":null,"Customer":[{"ObjectType":"contact","CustomerText":"Lim","CustomerValue":"e0203ac0-2a3d-de11-8641-0003ffc4d675"},{"ObjectType":"contact","CustomerText":"Contact B","CustomerValue":"a0ff10e6-1766-de11-8f5c-0003ffb4d763"},{"ObjectType":"contact","CustomerText":"Contact C","CustomerValue":"9088e0ec-1766-de11-8f5c-0003ffb4d763"}]}

What are the advantages of creating JSON string format ?

you can access those objects at the client side easily, in example :

function AccessArgument(arg)
{
  var jsonStringArgument = arg;
  var argument = eval(jsonStringArgument);

  var filterComboTypeValue = argument.FilterComboType;
  
  for(var i=0; i<argument.Customer.length; i++)
  {
    var customerValue = argument.Customer&#91;i&#93;.CustomerValue;
  }
}

&#91;/sourcecode&#93;

Notice how easily i'm accessing a list of the argument's Customer in array object at the client side

How do you convert from JSON string to the actual object itself ?

&#91;sourcecode='jscript'&#93;
var objectArgument = eval('a Json String');
&#91;/sourcecode&#93;

How do you convert from actual object back to the JSON string ? You need <a href="http://www.json.org/js.html">json2.js</a> which can be downloaded <a href="http://www.json.org/js.html">here</a> . The javascript file needs to be included in the html head.


var jsonText = JSON.stringify(objectArgument);

I like to use Newtonsoft JSON.NET to serialize my C# object to the JSON string format as well as deserialize my C# object back to the JSON string format

Here are the code sample how to serialize the Argument object into JSON string

txtAccountListJson.Text = Newtonsoft.Json.JavaScriptConvert.SerializeObject(newArg);

And here are the code sample in how to serialize the JSON string back to the actual object

Argument arg = (Argument)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(txtContactListJson.Text, typeof(Argument));

Create a free website or blog at WordPress.com.