Dynamics 365





Friday, April 18, 2014

CRM 2011 - Hide or Disable Button from ribbon

CRM 2011   Hide or Disable Button from ribbon

 

 Source:http://mscrmshop.blogspot.com/2011/07/step-by-step-hiding-add-existing-button.html

Here are the steps

  • Create a new solution.
  • Add the contact entity to the solution. Do not include any required components or dependent components to the solution.
  • Export the solution and unzip the solution file.
  • Open the customizations file and look for “<RibbonDiffXml>” tag.
  • Replace the <CustomActions /> with
<CustomActions>
  <HideCustomAction Location="Mscrm.SubGrid.contact.AddExistingAssoc" HideActionId="Mscrm.SubGrid.contact.AddExistingAssoc.HideAction" />
  <HideCustomAction Location="Mscrm.SubGrid.contact.AddExistingStandard" HideActionId="Mscrm.SubGrid.contact.AddExistingStandard.HideAction" />
</CustomActions>
  • Save the file.
  • Replace the customizaions.xml file in your zip solution with this file.
  • Import the solution and publish the changes.
Note: Replace the highlighted "contact” text with your entity name. It can be “opportunity” or a custom entity like “new_entity” etc.

 

Monday, January 20, 2014

Set Notification error messsage in CRM 2011


Please try below code instead of alert box it will be displayed on form.

set_Notification(2, 'source', 'Business Phone must contain 10 numbers.');

Tuesday, January 7, 2014

CRM 2011 - change Ribbon Button Name



Change button Name in ribbon - CRM 2011 dynamics.


Hi,
When we have relationship between two entities, the child entity link add to the left navigation of parent.
For example,
  • “Contacts” link add to the left navigation of “Accounts”
Contacts Associated View In Account Contacts Associated View In Account
The view we call it as “Associate View” and it contains buttons with below naming convention
  • “Add {Display name of child}” (i.e., “Add Contact” in above screen)
  • “Add Existing {Display name of child}” (i.e., “Add Existing Contact” in above screen)
To rename the “Add & Add existing” buttons below are the steps
  • Create a new solution
  • Add child entity (i.e., Contact) in above example
  • Export & Save solution in local folder
  • Extract folder and open “Customizations.XML” in Visual Studio
  • Find <RibbonDiffXml><CustomActions> node
  • Add below XML
          <CustomAction Id=”Mscrm.SubGrid.{Entity Name}.AddNewStandard.CustomAction” Location=”Mscrm.SubGrid.{Entity Name}.AddNewStandard” Sequence=”210″>
<CommandUIDefinition>
<!–New Button Id – AddNewStandard; Existing Button Id – AddExistingStandard–>
<Button Id=”Mscrm.SubGrid.{Entity Name}.AddNewStandard
Command=”Mscrm.AddNewRecordFromSubGridStandard”
Sequence=”20″
LabelText=”My Custom Text
Alt=”My Custom Text
Image16by16=”/_imgs/ribbon/NewRecord_16.png” Image32by32=”/_imgs/ribbon/newrecord32.png”
TemplateAlias=”o1″ ToolTipTitle=”Add New Contact”
ToolTipDescription=”$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipDescription” />
</CommandUIDefinition>
</CustomAction>
  • Save, zip & Export solution

 

 

Saturday, December 14, 2013

CRM 2011 - Auto populate values on lookup value selected - json ODATA

On Lookup up change get Account Entity values get auto populated using ODATA JSON script

function retrieveRecord() {

    var odataSetName = "AccountSet";
    debugger;
    var accountLookup = Xrm.Page.getAttribute("pmax_companyname1").getValue();
    if (accountLookup != null) {
        var AccountID = accountLookup[0].id;
    }
    // Get Server URL

    var serverUrl = Xrm.Page.context.getServerUrl();

    var serverUrl = "http://117.218.28.36/pmax-crm";

    //The OData end-point

    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

    //Asynchronous AJAX function to Retrieve a CRM record using OData
    debugger;
    $.ajax({

        type: "GET",

        contentType: "application/json; charset=utf-8", datatype: "json",

        url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + AccountID + "')",

        beforeSend: function (XMLHttpRequest) {

            //Specifying this header ensures that the results will be returned as JSON.

            XMLHttpRequest.setRequestHeader("Accept", "application/json");

        },

        success: function (data, textStatus, XmlHttpRequest) {

            readRecord(data, textStatus, XmlHttpRequest)

        },

        error: function (XmlHttpRequest, textStatus, errorThrown) {

            alert("Error – " + errorThrown)

        }

    });

}

    function readRecord(data, textStatus, XmlHttpRequest) {

    alert("Record read successfully!!");

    var account = data;

    alert("Name – " + account.d.Telephone1);
    alert("Name – " + account.d.WebSiteURL);

    Xrm.Page.getAttribute("pmax_website").setValue(account.d.WebSiteURL);
    Xrm.Page.getAttribute("pmax_website").setSubmitMode("always");

    Xrm.Page.getAttribute("pmax_businessphone").setValue(account.d.Telephone1);
    Xrm.Page.getAttribute("pmax_businessphone").setSubmitMode("always");
  

    }

Thursday, December 12, 2013

Default the Activities 'Filter on' to 'All' for Account and Contact - CRM 2011


Default the Activities 'Filter on' to 'All' for Account and Contact

 

//default the Activities 'Filter on' to 'All' for Account and Contact 

function filterAllActivities() {
    document.getElementById("navActivities").onclick = function () {
        loadArea("areaActivities"); 
        document.getElementById("areaActivitiesFrame").onload = function () {
            var entityName = Xrm.Page.data.entity.getEntityName();
            var entity = entityName.charAt(0).toUpperCase() + entityName.substr(1);
            var doc = this.contentWindow.document;
            var filterOn = doc.getElementById("crmGrid_" + entity + "_ActivityPointers_datefilter"); 
            filterOn.value = "All";
            filterOn.FireOnChange();
        };
    };

 

Monday, November 4, 2013

Close quote Plugin code in c#.net

Close quote Plugin code in c#.net

Below code to achieve logic 
  using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm.Sdk.Messages;
namespace CloseQuote
{
    public class PluginCloseQuote:IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            try
            {
                // Plugin to close the quote
                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.Depth<2)
                {
                    Entity entity = context.InputParameters["Target"] as Entity;

                    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = ((IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(new Guid?(context.UserId));


                    OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
                    Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains("PostImage")) ? context.PostEntityImages["PostImage"] : null;
                  
                    if (postImageEntity.GetAttributeValue<bool>("pmax_isclosequote"))
                    {
                     
                        if (((OptionSetValue)postImageEntity.Attributes["statecode"]).Value == 0)
                        {
                            //method to Activate quote
                            SetEntityStatus(service, entity.Id, "quote");

                        }
                       
                        //method to close quote
                        CloseQuoteRequest req = new CloseQuoteRequest();
                        Entity quoteClose = new Entity("quoteclose");
                        quoteClose.Attributes.Add("quoteid", new EntityReference("quote", entity.Id));
                        quoteClose.Attributes.Add("subject", "Customer was mean so we just closed it.");
                        req.QuoteClose = quoteClose;
                        req.RequestName = "CloseQuote";
                        OptionSetValue o = new OptionSetValue();
                        o.Value = 5;
                        req.Status = o;
                       
                        CloseQuoteResponse resp = (CloseQuoteResponse)service.Execute(req);
                    }
                    else if (postImageEntity.GetAttributeValue<bool>("pmax_isactivatequote"))
                    {
                        if (((OptionSetValue)postImageEntity.Attributes["statecode"]).Value == 0)
                        {
                            //method to Activate quote
                            SetEntityStatus(service, entity.Id, "quote");

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(
                   "An error occurred in the CloseQuote.PluginCloseQuote Plug-in" + ex.Message, ex);
            }
        }
        //activate the quote
        private void SetEntityStatus(IOrganizationService service, Guid recordGUID, string entityName)
        {

            SetStateRequest setState = new SetStateRequest();

            setState.EntityMoniker = new EntityReference();

            //Pass GUID of the record to be activated or Deactivated

            setState.EntityMoniker.Id = recordGUID;

            setState.EntityMoniker.Name = entityName;

            setState.EntityMoniker.LogicalName = entityName;

            //Setting ‘State’ i.e., (0 – Active ; 1 – InActive)

            setState.State = new OptionSetValue();

            setState.State.Value = 1;

            //Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)

            setState.Status = new OptionSetValue();

            setState.Status.Value = 3;

            SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);

        }
        private void SetEntityStatusActive(IOrganizationService service, Guid recordGUID, string entityName)
        {

            SetStateRequest setState = new SetStateRequest();

            setState.EntityMoniker = new EntityReference();

            //Pass GUID of the record to be activated or Deactivated

            setState.EntityMoniker.Id = recordGUID;

            setState.EntityMoniker.Name = entityName;

            setState.EntityMoniker.LogicalName = entityName;

            //Setting ‘State’ i.e., (0 – Active ; 1 – InActive)

            setState.State = new OptionSetValue();

            setState.State.Value = 3;

            //Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)

            setState.Status = new OptionSetValue();

            setState.Status.Value = 5;

            SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);

        }
        private SetStateRequest inactiveSuspect(Entity entSuspect)
        {
            //to set prospect record inactive
            //WinOpportunityRequest

           
            SetStateRequest setState = new SetStateRequest();

            setState.EntityMoniker = new EntityReference();

            //Pass GUID of the record to be activated or Deactivated

            setState.EntityMoniker.Id = entSuspect.Id;

            setState.EntityMoniker.Name = "quote";

            setState.EntityMoniker.LogicalName = entSuspect.LogicalName;

            //Setting ‘State’ i.e., (0 – Active ; 1 – InActive)

            setState.State = new OptionSetValue();

            setState.State.Value = 0;

            //Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)

            setState.Status = new OptionSetValue();

            setState.Status.Value = 1;


            return setState;
            //
        }
    }
}
 

Wednesday, September 11, 2013

SubGrid Refresh or SubGrid Attach even usig Java Script

 below peice of code to refresh the subgrid.
 
function SubGridLoadWait() {
    setTimeout(OnAccountFormLoad, 3000);
}

function OnAccountFormLoad() {
    //Set Action on subgrid Refresh
    //debugger;
    var subGrid = document.getElementById("SuspectGrid");
    //if(subGrid) {
    subGrid.attachEvent("onrefresh", getPrimaryRows);

    //SubGrid.attachEvent("onrefresh", CallbackFunction);
    //SubGrid.control.add_onRefresh(CallbackFunction);

    //}

}

//This function fires on subgrid refresh

function getPrimaryRows() {
    var isPrimaryYes = false;
    var isPrimaryNo = false;
    var gridControl = document.getElementById('SuspectGrid').control;
    var ids = gridControl.get_allRecordIds();
    for (i = 0; i < ids.length; i++) {

        var primary = gridControl.getCellValue('new_isprimarysuspect', ids[i]);
        if (primary=="Yes") {
            isPrimaryYes = true;
            break;
        }
        else if(primary=="No"){
            isPrimaryNo = true;
        }
    }
    if (isPrimaryYes) {

        Xrm.Page.getAttribute("new_canhaveprimarysuspect").setValue(true);
//        alert("Primary Suspect checked");
    }
    else if (isPrimaryNo) {
        Xrm.Page.getAttribute("new_canhaveprimarysuspect").setValue(false);
      //  alert("Primary Suspect unchecked");
    }
}