Wednesday, March 19, 2014

Create New Business Processes / Modify existing processes




There are 3 steps involved in creating or modifying the existing business process flows.

In this case, I’ll be adding a sample process flow to the contact entity.

  1. First step in the process is Adding the sales stage category values you need. i.e. the stage names. In the default solution, you will find an option set “processstage_category”. Add necessary values in the option set.
  2. Creating a Business Process Flow. Go to SettingsàProcessesàBusiness Process Flows. Create New. 
  3. Add the necessary stages and checks required for them.

The same can be done for OTB entities like Opportunity, Account etc. These Process flows can be controlled through security roles just like Forms.

Wednesday, February 19, 2014

Enable Proxy Types in Plugins

If you need to use Linq Queries in plugins/workflows, you have to enable proxy types before instantiating the service object from service provider.


factory.GetType().GetProperty("ProxyTypesAssembly").SetValue(factory,typeof(YourCrmContext).Assembly, null);



Friday, January 31, 2014

Ajax request from HTML to CRM2011/ CRM2013

var requestmain = fetchxml;

 $.ajax(
            {
                type: "POST",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: serverurl + "/XRMServices/2011/Organization.svc/web",
                async: false,
                data: requestMain,
                headers: { "Accept": "application/xml, text/xml, */*", "Content-Type": "text/xml; charset=utf-8", "SOAPAction": "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple" }

            })
            .done(function (XMLHttpRequest) {
                var strResponse = GetXmlValue(XMLHttpRequest.childNodes[0]);
                xmlDoc = $.parseXML(strResponse);
            })
            .fail(function (XMLHttpRequest) {
                alert("Error retrieving accounts using fetch xml");
            })
            .always(function (XMLHttpRequest) {
            });

function GetXmlValue(value) {
    if (value.xml == undefined) {
        return (new XMLSerializer()).serializeToString(value);
    }
    return value.xml;
}
 

Friday, August 24, 2012

FormEntityContextRule Example



 CustomActions:

        <CustomActions>
          <CustomAction Id="Mscrm.SubGrid.new_test.AddExistingAssocCustom" Location="Mscrm.SubGrid.new_test.AddExistingStandard" Sequence="30" >
            <CommandUIDefinition>
              <Button Id="Mscrm.SubGrid.new_test.AddExistingStandard" Command="Mscrm.AddExistingRecordFromSubGridStandardCustom" Sequence="30" LabelText="CustomAddExistingStd" Alt="$Resources(EntityDisplayName):Ribbon.SubGrid.AddExisting" Image16by16="/_imgs/ribbon/AddExistingStandard_16.png" Image32by32="/_imgs/ribbon/AddExistingStandard_32.png" TemplateAlias="o1" ToolTipTitle="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddExistingStandard_ToolTipTitle" ToolTipDescription="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddExistingStandard_ToolTipDescription" />
            </CommandUIDefinition>
          </CustomAction>

          <CustomAction Id="Mscrm.SubGrid.new_test.AddNewStandardCustom" Location="Mscrm.SubGrid.new_test.AddNewStandard" Sequence="20" >
            <CommandUIDefinition>
              <Button Id="Mscrm.SubGrid.new_test.AddNewStandard" Command="Mscrm.AddNewRecordFromSubGridStandardCustom" Sequence="20" LabelText="CustomAddNewStd" Alt="$Resources(EntityDisplayName):Ribbon.SubGrid.AddNew" Image16by16="/_imgs/ribbon/NewRecord_16.png" Image32by32="/_imgs/ribbon/newrecord32.png" TemplateAlias="o1" ToolTipTitle="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipTitle" ToolTipDescription="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipDescription" />
            </CommandUIDefinition>
          </CustomAction>
        </CustomActions>



CommandDefinitions:

        <CommandDefinitions>
          <CommandDefinition Id="Mscrm.AddExistingRecordFromSubGridStandardCustom">
            <EnableRules>
              <EnableRule Id="Mscrm.AppendToPrimary" />
              <EnableRule Id="Mscrm.EntityFormIsEnabled" />
            </EnableRules>
            <DisplayRules>
              <DisplayRule Id="Mscrm.AddExisting" />
              <DisplayRule Id="Mscrm.ShowForOneToManyGrids" />
              <DisplayRule Id="Mscrm.AppendToPrimary" />
              <DisplayRule Id="Mscrm.AppendSelected" />
              <DisplayRule Id="Mscrm.CanWriteSelected" />
              <DisplayRule Id="Mscrm.CustomShow" />
            </DisplayRules>
            <Actions>
              <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addExistingFromSubGridStandard" Library="/_static/_common/scripts/RibbonActions.js">
                <CrmParameter Value="SelectedEntityTypeCode" />
                <CrmParameter Value="SelectedControl" />
              </JavaScriptFunction>
            </Actions>
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.AddNewRecordFromSubGridStandardCustom">
            <EnableRules>
              <EnableRule Id="Mscrm.AppendToPrimary" />
              <EnableRule Id="Mscrm.EntityFormIsEnabled" />
            </EnableRules>
            <DisplayRules>
              <DisplayRule Id="Mscrm.ShowForOneToManyGrids" />
              <DisplayRule Id="Mscrm.AppendToPrimary" />
              <DisplayRule Id="Mscrm.CreateSelectedEntityPermission" />
              <DisplayRule Id="Mscrm.AppendSelected" />
              <DisplayRule Id="Mscrm.HideAddNewForChildEntities" />
              <DisplayRule Id="Mscrm.CustomShow" />
            </DisplayRules>
            <Actions>
              <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addNewFromSubGridStandard" Library="/_static/_common/scripts/RibbonActions.js">
                <CrmParameter Value="SelectedEntityTypeCode" />
                <CrmParameter Value="PrimaryEntityTypeCode" />
                <CrmParameter Value="FirstPrimaryItemId" />
                <CrmParameter Value="PrimaryControl" />
              </JavaScriptFunction>
            </Actions>
          </CommandDefinition>
        </CommandDefinitions>


RuleDefinition:
        <RuleDefinitions>
          <TabDisplayRules />
          <DisplayRules>
            <DisplayRule Id="Mscrm.CustomShow" >
              <FormEntityContextRule EntityName="account" InvertResult="true" />
            </DisplayRule>
          </DisplayRules>
          <EnableRules />
        </RuleDefinitions>

open link url inside a div/iframe

<html>
<head>
<script type="text/javascript">

function  showPage (which) {
    document.getElementById('xrmforms').innerHTML = '<' + 'iframe id="crmpage" src="' + which + '"width="100%" height="600px;" scrolling="auto"></iframe>';

}

</script>

</head>
<body>
<a href="http://www.google.com" onclick="showPage(this.href);return false;">Click here</a>


<div id="xforms">
</div>

</body>
</html>








Replace certain character JavaScript

To replace certain characters in javascript:

In this example, i'm replacing '&' with '&amp;' in the entire string.


function formatTexts(linkText) {
    var patt1 = /&/g;
    var patt1replStr = "&amp;";

    var matchPatt = linkText.match(patt1);

    var pattformat = /&amp;/g;
    var matchformatted = "";
    if (matchPatt != null && matchPatt.length > 0) {
        while (matchformatted.length < matchPatt.length) {
            linkText = linkText.replace(linkText.match(patt1)[0], patt1replStr);
            matchformatted = linkText.match(pattformat);
        }
    }
    return linkText;
}

HtmlEncoding in Javascript


Often when executing fetchxml in javascript or when creating tables throught javascript, you would face the error because the values are not htmlencoded.


function htmlEncode(value) {
    return $('<div/>').text(value).html();
}
function htmlDecode(value) {
    return $('<div/>').html(value).text();
}


This encodes the default characters that have to be encoded.
For more details:
http://support.microsoft.com/kb/316063

Hide CrmNavBar and CrmRibbon through javascript

//This toggles ribbon visibility, but doesnt move the form area up
window.top.document.getElementById("minimizeribbon").fireEvent("onclick");


// Hide the Ribbon toolbar and move the form Content area to the top of the window.
window.top.document.getElementById("crmTopBar").style.display = "none";
window.top.document.getElementById("crmContentPanel").style.top = "0px"; //

//default values for showing ribbon and moving content area below ribbon

window.top.document.getElementById("crmTopBar").style.display = "";
window.top.document.getElementById("crmContentPanel").style.top = "135px"; //



// Hide Left Hand Nav bar / pane
document.getElementById("crmNavBar").parentElement.style.display = "none";
document.getElementById("tdAreas").parentElement.parentElement.parentElement.parentElement.colSpan = 2;



// Hide the Breadcrumb and Record Set Toolbar
document.getElementById("recordSetToolBar").parentElement.style.display = "none";

// Hide the Form Footer Bar
document.getElementById("crmFormFooter").parentElement.style.display = "none";




Tuesday, May 8, 2012

Parse Json in Silverlight

            string jsonstring = "";//Must be a Json String
            byte[] inputarray = Encoding.UTF8.GetBytes(jsonstring);
            MemoryStream stream = new MemoryStream(inputarray);
            StreamReader reader = new StreamReader(stream);
           
            XmlDictionaryWriter xmlData = JsonReaderWriterFactory.CreateJsonWriter(reader.BaseStream);

Friday, March 16, 2012

Modifying System Ribbon button functionality CRM 2011


I found ribbons in 2011 the most painful part, till i learnt how to use it. It is actually cooler than in CRM4. To modify a system button functionality: All that we need to do here is copy the button ID as is from exportedribbonxml available from  sdk\samplecode\cs\client\ribbon\exportribbonxml\exportedribbonxml\myentityribbon.xml.
In this case, i'm gonna modify my email form's send button functionality. The button definition from emailribbon.xml looks like:

<Button Id="Mscrm.Form.email.Send" Command="MSCRM.Form.email.Send.CustomCommand" Sequence="1" Alt="$Resources:Ribbon.Form.email.MainTab.Actions.Send" LabelText="$Resources:Ribbon.Form.email.MainTab.Actions.Send" Image16by16="/_imgs/SFA/SendAsEmail_16.png" Image32by32="/_imgs/SFA/SendAsEmail_32.png" TemplateAlias="o1" ToolTipTitle="$Resources:Mscrm_Form_email_MainTab_Actions_Send_ToolTipTitle" ToolTipDescription="$Resources:Mscrm_Form_email_MainTab_Actions_Send_ToolTipDescription" />

Add that buttondefinition as we would do for adding any custom button. Just match the location attribute of the Customaction tag for the button with the button ID.
i.e.  Change your CustomAction's location attribute

<CustomAction Id="Mscrm.Form.email.Send.CustomAction" Location="Mscrm.Form.email.Send" Sequence="1"><CommandUIDefinition><Button Id="Mscrm.Form.email.Send" Command="MSCRM.Form.email.Send.CustomCommand" Sequence="1" Alt="$Resources:Ribbon.Form.email.MainTab.Actions.Send" LabelText="$Resources:Ribbon.Form.email.MainTab.Actions.Send" Image16by16="/_imgs/SFA/SendAsEmail_16.png" Image32by32="/_imgs/SFA/SendAsEmail_32.png" TemplateAlias="o1" ToolTipTitle="$Resources:Mscrm_Form_email_MainTab_Actions_Send_ToolTipTitle" ToolTipDescription="$Resources:Mscrm_Form_email_MainTab_Actions_Send_ToolTipDescription" /></CommandUIDefinition></CustomAction>

After this, i define a Commanddefinition MSCRM.Form.email.Send.CustomCommand inside my command definition tag.

<CommandDefinition Id="MSCRM.Form.email.Send.CustomCommand">            <EnableRules><EnableRule Id="Mscrm.UserHasRoleForSend"/>            </EnableRules><DisplayRules><DisplayRule Id="Mscrm.CanWritePrimary" />              <DisplayRule Id="Mscrm.Form.email.InDraftOrFailedState" /></DisplayRules><Actions><JavaScriptFunction FunctionName="send" Library="/_static/activities/email.js" /></Actions></CommandDefinition>

After this, i define my customrule "Mscrm.UserHasRoleForSend" inside a javascript.

<EnableRules><EnableRule Id="Mscrm.UserHasRoleForSend"><CustomRule FunctionName="UserHasRoleForSend" Library="$webresource:customscripts_CheckUserRoleForMarketingList.js" /></EnableRule></EnableRules>

customscripts_CheckUserRoleForMarketingList.js is a webresource jscript that i've already uploaded. I'm calling a function UserHasRoleForSend in customscripts_CheckUserRoleForMarketingList.js. The function returns a true or false value.
Since the display rules are inbuilt i'm not redefining them in my customizations.xml.
Note: If not required, we can remove the displayrules from the custom command. In my case, i just needed to add an additional condition for enabling the "send" button in email form. The same can be done for HomePageGrid buttons also.