Showing posts with label crm 2011. Show all posts
Showing posts with label crm 2011. Show all posts

Sunday, October 16, 2011

How to trigger "onchange" event for the fields in locked section

There is  "Scheduling Information" section on  Appointment and Service Activity entity forms.
You can not  change the properties of the fields in this section. You cannot add javascript to "OnChange" events of these fields. If you double click on any of the field in this section, you will get a message "You can not modify the properties of this element because it is with in a locked section"
















So how can you add javascript to onchange event on these fields? It is simple and here is what I did to achieve this.
  • Add a new tab to the form.
  • In the visibility section of tab unctick the "Visible by default" checkbox .


























  • In the field explore window untick "Only shows unused fields". It will display all the available entity  fields in the list.
  • Add the fields to this newly created tab. ( Fields that are also present on the locked section)
  • Add the "On Change" event to one of the field.
  • Save the changes and publish the entity.
  • Now if you change the value of field in the locked section, it will trigger the event you defined in the newly created tab's field.

Wednesday, June 8, 2011

How to start a Dialog from Application Ribbon (CRM 2011)

To start the Dialog from the Application Ribbon, you need to 3 things
  1. Application Ribbon Button (and Button Images)
  2. JavaScript to call the Dialog
  3. Dialog
I have attached the unmanaged solution here. The solution contains the following components
image
  • “Application Ribbons” contains the definition of the button.
  • “new_custom16x16” and “new_custom32x32” are image files for the button.
  • “new_dialogjavascript” is a JavaScript web Resource. It contains the JavaScript code to open the dialog.
  • “Sales Call” is dialog script

Detail Explanation

Application Ribbon

   1:  <RibbonDiffXml>
   2:      <CustomActions>
   3:        <CustomAction Id="Sample.{!EntityLogicalName}.MainTab.MyURL.CustomAction" Sequence="41" Location="Mscrm.HomepageGrid.{!EntityLogicalName}.MainTab.Workflow.Controls._children">
   4:          <CommandUIDefinition>
   5:            <Button Id="Sample.{!EntityLogicalName}.MainTab.MyURL.Button" Command="javascript.Command" LabelText="Sales Call" ToolTipTitle="Sales Call" ToolTipDescription="Sales Call" TemplateAlias="o1" Image16by16="$webresource:new_custom16x16" Image32by32="$webresource:new_custom32x32" />
   6:          </CommandUIDefinition>
   7:        </CustomAction>
   8:      </CustomActions>
   9:      <Templates>
  10:        <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
  11:      </Templates>
  12:      <CommandDefinitions>
  13:        <CommandDefinition Id="javascript.Command">
  14:          <EnableRules>
  15:            <EnableRule Id="Mscrm.Enabled"/>
  16:          </EnableRules>
  17:          <DisplayRules />
  18:          <Actions>
  19:            <JavaScriptFunction
  20:                Library="$webresource:new_dialogjavascript"
  21:                FunctionName="callDialog">
  22:            </JavaScriptFunction>
  23:          </Actions>
  24:        </CommandDefinition>
  25:      </CommandDefinitions>
  26:      <RuleDefinitions>
  27:        <TabDisplayRules />
  28:        <DisplayRules />
  29:        <EnableRules />
  30:      </RuleDefinitions>
  31:      <LocLabels />
  32:    </RibbonDiffXml>
  • “CustomAction” tag define the location of the button ( which entity, which group, sequence etc).
  • “Button” tag defines the text, images, tooltip of the button. The most import attribute of “Button” tag is “Command”. In this solution Command = javascript.Command.
  • “CommandDefinition” tag defines the javascript.Command mentioned in “Button” tag.
  • <EnableRule Id="Mscrm.Enabled"/> this line makes the button enabled on the ribbon.
  • “Actions” tag defines which JavaScript webresource and which function in that webresource will be called on button click.
Note: If you already a custom app ribbon button in your solution and you import any other unmanaged solution with “Application Ribbon” file in it. it will over write your custom button. Take a backup of your solution before you import any unmanaged solution.
    function getOrg() {
        ///<summary>
        /// get organisation
        ///</summary>
      
        var Org = "";
        if (typeof GetGlobalContext == "function") {
            var context = GetGlobalContext();
            Org = context.getOrgUniqueName();
        }
        else {
            if (typeof Xrm.Page.context == "object") {
                Org = Xrm.Page.context.getOrgUniqueName();
            }
            else
            { throw new Error("Unable to access Organisation name"); }
        }
       
        return Org;
    }

    function getUser() {
        ///<summary>
        /// get logged in user
        ///</summary>
      
        var User = "";
        if (typeof GetGlobalContext == "function") {
            var context = GetGlobalContext();
            User = context.getUserId();
        }
        else {
            if (typeof Xrm.Page.context == "object") {
                User = Xrm.Page.context.getUserId();
            }
            else
            { throw new Error("Unable to access the UserId"); }
        }
      
        return User;
    }

    function callDialog() {
    
    var url="/" + getOrg() + "/cs/dialog/rundialog.aspx?DialogId=%7bB7D825D7-7EF6-4713-AC11-284546FEB260%7d&EntityName=systemuser&ObjectId=" + getUser();
    window.open(url, "", "status=no,scrollbars=no,toolbars=no,menubar=no,location=no");
    //window.open(url);

    }
The JavaScript Webresource has three function
  • getOrganisation() – to get context organisation
  • getUser()-to get the logged in user
  • callDialog()- will call the dialog. you can change the DialogId to call your own dialog.
This example is using a dialog attached to the user entity, so we don’t need to create any record to run the dialog. The code picks up the logged in user and run the process.
Sales Call Dialog

Sales Call dialog is very simple but meaningful dialog process. Steps are as follow.
  1. Ask for customers first name and last name
  2. Ask if customer exist in the system
    • Search for the customer
  3. Else ask for address information
  4. Ask for the product customer is interested in
  5. Ask if sales rep want to create relevant records. if sales rep select yes create the contact and/or opportunity records.

Note: This dialog does not add product to the opportunity.

Here are some screen shots

image


 
image

 
image

 
Bye…………...

Tuesday, October 26, 2010

Step by step plugin tutorial for CRM 2011

This is a step by step guide to create a plug-in in CRM 2011.

1. Create a class library project in vs2010.
2. Sign the assembly by using the Signing tab of the project's properties sheet.
3. Add references to microsoft.crm.sdk.proxy , Microsoft.xrm.sdk ,
System.ServiceModel and System.Runtime.Serialization.
4. Here is code for this tutorial. This plugin will check if the account number
field is empty, create a task for the user to fill this up.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Microsoft Dynamics CRM namespace(s)
using Microsoft.Xrm.Sdk;
using System.ServiceModel;

namespace CRMPlugin1
{
public class createNote:IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{

// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));


// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];



try
{
//check if the account number exist

if (entity.Attributes.Contains("account number") == false)
{

//create a task
Entity task = new Entity("task");
task["subject"] = "Account number is missing";
task["regardingobjectid"] = new EntityReference("account",new Guid(context.OutputParameters["id"].ToString()));

//adding attribute using the add function
// task["description"] = "Account number is missng for the following account. Please enter the account number";
task.Attributes.Add("description", "Account number is missng for the following account. Please enter the account number");



// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


// Create the task in Microsoft Dynamics CRM.
service.Create(task);


}
}

catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}

}

}
}//end class
}//end name space


5. Compile the code and register it on the registration tool provided with sdk.
6. Register it on the post create event of account entity.
Note :check the sdk for instructions to register a plugin

Thanks