Skip to content

Clone custom entity in on primise instance


function GetContext() {
var _context = null;
if (typeof GetGlobalContext != “undefined”)
_context = GetGlobalContext();
else if (typeof Xrm != “undefined”)
_context = Xrm.Page.context;
return _context
}
function CloneTime() {

if (XP.data.entity.getId() == null) {
alert(‘First save the record before Clone Case’)

}
else {

var CRMContext = GetContext();
var serverUrl = CRMContext.getClientUrl();
var timeid = XP.data.entity.getId();
timeid= timeid.replace(‘{‘, ”).replace(‘}’, ”);

var url = serverUrl + ‘/main.aspx?etc=10010&extraqs=%3f_CreateFromId%3d%257b’ + timeid + ‘%257d%26_CreateFromType%3d10010%26etc%3d10010%26preloadcache%3d1399991348965&histKey=721725632&pagetype=entityrecord’;

window.open(url, “DisplayPopup”, ‘toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=’ + 1200 + ‘, height=’ + 600 + ‘, top=’ + 50 + ‘, left=’ + 50, true);

}
}

 

 

 

 

Advertisements

Calculate child records sum 1:N relationship


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
namespace Aggregate
{
public class CalculateSum : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
# region service intialization
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

// Get a reference to the organization service.
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
#endregion

try
{
if (context.Depth == 1)
{
string messageName = context.MessageName.ToUpper();
if (messageName == “CREATE”)
{
UpdateOpportunityValueQuoteCreate(context, service);

}
if (messageName == “UPDATE”)
{
UpdateOpportunityValueQuoteUpdate(context, service);
}
if (messageName == “DELETE”)
{
UpdateOpportunityValueQuoteDelete(context, service);

}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message.ToString());
}
}

 

private void UpdateOpportunityValueQuoteCreate(IPluginExecutionContext context, IOrganizationService service)
{
Guid OpportunityId = new Guid();
int total = 0;

if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is Entity)
{

Entity targetEntity = (Entity)context.InputParameters[“Target”];
if (targetEntity.LogicalName != “quote”)
return;

if (!targetEntity.Attributes.Contains(“new_opportunity”))
return;
OpportunityId = ((EntityReference)(targetEntity.Attributes[“new_opportunity”])).Id;

if (!targetEntity.Attributes.Contains(“new_quotetotal”))
return;
total = (Int32)targetEntity[“new_quotetotal”];

string fetchXml = @”<fetch version=””1.0″” output-format=””xml-platform”” mapping=””logical”” distinct=””false””>
<entity name=””opportunity””>
<attribute name=””new_total”” />
<filter type=””and””>
<condition attribute=””opportunityid”” operator=””eq”” value=””” + OpportunityId + @””” />
</filter>
</entity>
</fetch>”;

EntityCollection OpportunityRecords = service.RetrieveMultiple(new FetchExpression(fetchXml));

if (OpportunityRecords.Entities.Count > 0)
{
foreach (Entity entity in OpportunityRecords.Entities)
{
Entity Opportunity = new Entity(“opportunity”);
Opportunity.Id = OpportunityId;
//var opptotal = entity.GetAttributeValue<Int32?>(“new_total”).Value;
if (entity.Attributes.Contains(“new_total”))
// if (entity != null && entity.GetAttributeValue<Int32?>(“new_total”).Value == 0)
{

Opportunity[“new_total”] = (Int32)entity[“new_total”] + total;
service.Update(Opportunity);

}
else {

Opportunity[“new_total”] = total;
service.Update(Opportunity);
}
}

}

}
}

private void UpdateOpportunityValueQuoteUpdate(IPluginExecutionContext context, IOrganizationService service)
{
Guid OpportunityId = new Guid();
int total = 0;
int pretotal = 0;

if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is Entity)
{
Entity targetEntity = (Entity)context.InputParameters[“Target”];
Entity PostImage = (Entity)context.PostEntityImages[“PostImage”];
Entity PreImage = (Entity)context.PreEntityImages[“PreImage”];
if (PostImage.LogicalName != “quote”)
return;

if (!PostImage.Attributes.Contains(“new_opportunity”))
return;
OpportunityId = ((EntityReference)(PostImage.Attributes[“new_opportunity”])).Id;
if (!PostImage.Attributes.Contains(“new_quotetotal”))
return;
total = (Int32)PostImage[“new_quotetotal”];
if (PreImage.Attributes.Contains(“new_quotetotal”))
pretotal = (Int32)PreImage[“new_quotetotal”];

string fetchXml = @”<fetch version=””1.0″” output-format=””xml-platform”” mapping=””logical”” distinct=””false””>
<entity name=””opportunity””>
<attribute name=””new_total”” />
<filter type=””and””>
<condition attribute=””opportunityid”” operator=””eq”” value=””” + OpportunityId + @””” />
</filter>
</entity>
</fetch>”;

EntityCollection OpportunityRecords = service.RetrieveMultiple(new FetchExpression(fetchXml));

if (OpportunityRecords.Entities.Count > 0)
{
foreach (Entity entity in OpportunityRecords.Entities)
{
Entity Opportunity = new Entity(“opportunity”);
Opportunity.Id = OpportunityId;
Opportunity[“new_total”] = (Int32)entity[“new_total”] + total – pretotal;
service.Update(Opportunity);

}
}

}

}

 

 

private void UpdateOpportunityValueQuoteDelete(IPluginExecutionContext context, IOrganizationService service)
{
Guid OpportunityId = new Guid();
//int total = 0;
int pretotal = 0;

if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is EntityReference)
{
EntityReference targetEntity = (EntityReference)context.InputParameters[“Target”];
//Entity PostImage = (Entity)context.PostEntityImages[“PostImage”];
Entity PreImage = (Entity)context.PreEntityImages[“PreImage”];

if (targetEntity.LogicalName != “quote”)
return;

//if (context.PreEntityImages.Contains(“PreImage”) && context.PreEntityImages[“PreImage”] is Entity)
// {
if (!PreImage.Attributes.Contains(“new_opportunity”))
return;
//Entity PreImage = (Entity)context.PreEntityImages[“PreImage”];
//if (!PreImage.Attributes.Contains(“quoteid”))
// return;
OpportunityId = ((EntityReference)(PreImage.Attributes[“new_opportunity”])).Id;
if (!PreImage.Attributes.Contains(“new_quotetotal”))
return;
//total = (Int32)PostImage[“new_quotetotal”];
//if (!PreImage.Attributes.Contains(“new_quotetotal”))
// return;
pretotal = (Int32)PreImage[“new_quotetotal”];

string fetchXml = @”<fetch version=””1.0″” output-format=””xml-platform”” mapping=””logical”” distinct=””false””>
<entity name=””opportunity””>
<attribute name=””new_total”” />
<filter type=””and””>
<condition attribute=””opportunityid”” operator=””eq”” value=””” + OpportunityId + @””” />
</filter>
</entity>
</fetch>”;

EntityCollection OpportunityRecords = service.RetrieveMultiple(new FetchExpression(fetchXml));

if (OpportunityRecords.Entities.Count > 0)
{
foreach (Entity entity in OpportunityRecords.Entities)
{
Entity Opportunity = new Entity(“opportunity”);
Opportunity.Id = OpportunityId;
Opportunity[“new_total”] = (Int32)entity[“new_total”] – pretotal;
service.Update(Opportunity);

}
}

}

}
}
}
//}

Clone in Mscrm 2013


function GetContext() {
var _context = null;
if (typeof GetGlobalContext != “undefined”)
_context = GetGlobalContext();
else if (typeof Xrm != “undefined”)
_context = Xrm.Page.context;
return _context
}
function cloneCase() {

if (Xrm.Page.data.entity.getId() == null) {
alert(‘First save the record before Clone Case’)

}
else {

var CRMContext = GetContext();
var serverUrl = CRMContext.getServerUrl();
var caseid = Xrm.Page.data.entity.getId();
caseid = caseid.replace(‘{‘, ”).replace(‘}’, ”);

//Below URL is for CRM online
var url = serverUrl + ‘main.aspx?etc=112&extraqs=%3f_CreateFromId%3d%257b’ + caseid + ‘%257d%26_CreateFromType%3d112%26etc%3d112%26pagemode%3diframe&pagetype=entityrecord’;

window.open(url, “DisplayPopup”, ‘toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=’ +1200 + ‘, height=’ + 600 + ‘, top=’ + 50+ ‘, left=’ + 50, true);

}

}

Global Search in Mscrm


http://www.mindfiresolutions.com/downloads.htm#Dynamics_CRM_2011-Global_Search

Controlling the Lead Qualification process in CRM 2013


CRM 2013 (Orion) removed the Convert Lead dialog box from the Lead Qualification process. While migrating to the Orion instance, this is becoming a roadblock for us as the product doesn’t give the option of controlling which entity records to create upon Lead qualification.

Orion directly creates all the three entity records – Account, Contact and Opportunity as a part of lead qualification process, thus removing the flexibility from the user of selecting the entity records that needs be created. The product however checks for possible duplicates for Account and Contact records but the process isn’t favored by many and the risk of creating duplicate records or associating lead and opportunity to incorrect Account/Contact cannot be neglected.

I mentioned it as a roadblock for us because we have several business rules on lead qualification process wherein we don’t create Opportunity and Account record for a couple of qualification reasons.

In order to implement the same business rules in CRM 2013 Orion, I was researching a way to restrict the create of Opportunity/Account record for specific lead qualification status reason.

Here’s a simple way to do it –

Write a PreValidation plugin on the QualifyLead message for the Lead entity. Based on a certain condition, change the plugin context as follows

// Requirement – if the lead qualification reason is 100000021, do not create account and opportunity records
if (((OptionSetValue)(context.InputParameters["Status"])).Value == 100000021) // status is the lead qualification reason selected by the user
{
     context.InputParameters["CreateOpportunity"] = false; // set to true by default
      context.InputParameters["CreateAccount"] = false; // set to true by default
}

The InputParameters collection in the plugin context contains the key-value pairs for Account (CreateAccount), Contact (CreateContact) and Opportunity (CreateOpportunity). As shown in the above code, we can change these values to false under specific condition and hence restrict/control the unnecessary record creation.

Microsoft Dynamics CRM 2013 – Business Process Flow


Microsoft Dynamics CRM 2013 – Business Process Flow 

In this article, I will explore the new Business Process Flow (BPF) feature and provide some examples of how you can customize it to fit an organization’s need. 

Dynamics CRM 2013, BPFs have many beneficial qualities.  They are available for out-of-the-box (OOB) and custom entities, can span across multiple entities, you can create multiple BPFs for a particular business process, can be role based, can be included in solutions for export and import, and work in the browser, Outlook Client and Tablets

A key purpose of a BPF is to guide users through a specific business process to completion.  A BPF is useful in several ways to include but not limited to:

  • Highly configurable to meet the needs of any Organization
  • Ensure that a set of steps are completed for a specified business process
  • Jump stages if needed
  • Track and report on progress
  • Support the establishment of efficient, effective and repeatable processes
  • Guide existing and new employees through the process
  • Support quick, on-boarding of new hires

Microsoft Dynamics CRM 2013 comes with three OOB BPF’s; two are related to sales and one to service.  Let’s begin by briefly exploring the out-of-the-box Phone to Case BPF. 

To view the OOB BPF’s, select Settings and Processes from the top navigation menu.

 

Select All Processes and open the Phone to Case BPF

 

Before proceeding, let’s make a copy of the BPF by selecting the Save As button from the top navigation menu.

 

After making the selection, a new BPF window will open with a newly created BPF named Phone to Case Process (Copy).  The new process will be in draft or inactive status.  We can change the name of the process by selecting the Expand / Collapse chevron from the right side of the process window.

 

Let’s change the Process Name to “Case Resolution” by replacing “Phone to Case Process (Copy)” with the new name.  Select Save from the top navigation menu and then select the Collapse chevron. 

When viewing the Case Resolution Process BPF, you will notice that there are three stages; Identify, Research, Resolve.  Each one of the stages contains multiple steps.  For example, the Identify Stage includes two Steps; Find a Customer, Find a Case.

 

Let’s take a look at what the Identify Stage looks like on a new Case record.  To create a new case record, select Service and Cases from the top navigation menu.  Select the Identify process stage from the newly created Case to view the steps:

 

From here you can complete a lookup for the Customer and Find any similar cases.  Completing those two steps, completes the Identify stage.

Next, let’s make some changes to the new BPF we created.

The first change we’ll complete is to make all of the steps in the Identify, Research and Resolve stages required with the exception of Assign to Others in the Research stage.  To do this, select the Required option on each of the Steps.

 

Next we are going to add a new Stage and name it Propose Solution.  You can add a new Stage by selecting the plus button next to the word Stages.

 

Once selected, a new Stage will be added to the bottom of the Stage list. Let’s update the name to Propose Solution, select Propose for the Stage Category, update Steps to display “Suggest a Solution”, select “Activities Complete” for the Field Value, and mark the Step as required.

 

The next change I want to make is to move the Propose Solution above the Resolve stage.  I can easily make that change by selecting the Move Up option from the bottom of the process form.

 

Once that is complete, our new BPF displays the Stages in the required order with resolve being the final stage in the process.

 

After completing the changes desired to the BPF, there are a few additional steps required to make the new process available for use. 

The first step step we’ll take is to enable security roles.  Select the Enable Security Roles button from the top menu.

 

 

Select the Enable for Everyone option and select OK. 

 

Now let’s change the order of the BPFs so our new BPF displays by default.  Select the Order Process Flow button.

 

Select the Case Resolution BPF from the list, select the green, Move Up arrow and select OK.

 

The final step is to Activate the process by selecting the Active button from the top menu.

 

The new BPF will apply to all newly created Cases,  by default, since we moved it to the top of the list. 

If you choose, you can apply the new Case Resolution BPF to existing Case records by opening a Case record, select the More button from the command bar, select the Switch Process from the drop down list and select the Case Resolution BPF from the list.

 

Be sure to test your new BPF by creating a new Case to ensure everything is working as expected.  You can make any additional changes needed by simply opening the BPF record.

I hope you enjoy the Microsoft Dynamics CRM 2013 Business Process Flow feature.   Be sure to share your favorite BPF features, tips and tricks with us. 

 

 

http://blogs.msdn.com/b/mvpawardprogram/archive/2013/11/11/microsoft-dynamics-crm-2013-business-process-flow.aspx

QUICK FORMS IN MSCRM 2013


 

 
Quick Forms:
 
A quick form is a special type of CRM form that gives you the ability to display data from related entities onto the main form of any entity.
 
Quick forms will also be known as “Quick View Forms” since this form can be placed inside other main forms. They are rendered as read only so that quick form’s fields are not editable when placed on another form
 
Features:
 
·         These forms can be exported/imported as part of solutions.
·         These forms can be created/updated or deleted through the SDK.
·         Quick forms can be created/modified using the main form editor.
·         Only sections, spacers, fields and subgrids can be added.
·         A single column tab is used for quick forms and this cannot be changed.
·         No iframe or webresources are allowed.
·         Notes controls are not allowed.
·         There is no header or footer in quick forms.