CRM 2016 Interactive Service hub Form

Interactive Service hub is really an interactive feature introduced in CRM 2016. This enables you to view the records/update them faster in an interactive interface.

Interactive Service hub can be well viewed by copying the <orgnurl> followed by “/engagementhub.aspx” Eg: http://<orgnurl>/engagementhub.aspx or by clicking “Experience it now” from the Message:

EnableIntExp1

This can be enabled from the solution by clicking on “Enable for interactive experience” for both System as well as Custom entities

EnableIntExp

Interactive Forms can be created by selecting the Form type as “Main Form-Interactive experience” from the Solution while creating.

Enjoy an all new interface with this functionality.

 

CRM 2013 Trigger Plugin from Actions

Hi all,

With older versions of CRM till 2011, I felt difficult triggering a Plugin from ribbon button. We used to create a JScript that updates a field which in-turn calls the Plugin. This was bit complicated, but in the newer versions of CRM (2013/2015), Microsoft has introduced a new functionality called “Actions” which is similar to your System Workflows.

Here I will explain how to trigger a Plugin from actions simply without using any fields.

I am going to create an Action by navigating to Settings > Processes > New

Action

Dont forget to choose Action as the Category Type

Once clicked OK, the Action Window opens up. Over there you can see a field Unique Name. Make a note of this as you need to pass this exact Unique Name in Jscript. Here I am not passing any Input/Output Parameters.

Action Page

Next step is to Activate the Action.

Note: In your Plugin code, make the Target as EntityReference instead Entity.

PluginCode

Once Plugin is built successfully, go to Plugin Registration Tool where you can see the created Action’s Unique Name as a Message. Select this as Message and choose the entity.

Plugin

Now copy this JScript onto a Web Resource:

(Kindly search for &#8221; from this JScript and remove them as this Site is adding this content itself in all URLs)

function ribbonAction()
{
var formType = Xrm.Page.ui.getFormType();

if(formType == “2”)
{
// Creating the request XML for calling the Action
requestName = “new_triggerplugin”; //Unique Name of the Action Created
stringParameter = null;
var requestXML = “”
var entityId = Xrm.Page.data.entity.getId(); //GUID of the Current Record
var entityName = “new_entity”; //Entity Schema Name

var ServicePath = “https://crmdev.local/dev/XRMServices/2011/Organization.svc/web&#8221;; //Organization Service url followed by “/web”

if (stringParameter == null)
{
requestXML += “<s:Envelope xmlns:s=\”http://schemas.xmlsoap.org/soap/envelope/\”>”;
requestXML += ” <s:Body>”;
requestXML += “<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;
requestXML += “<request xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\”>”;
requestXML += “<a:Parameters xmlns:b=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;
requestXML += ” <a:KeyValuePairOfstringanyType>”;
requestXML += ” <b:key>Target</b:key>”;
requestXML += ” <b:value i:type=\”a:EntityReference\”>”;
requestXML += ” <a:Id>” + entityId + “</a:Id>”;
requestXML += ” <a:LogicalName>” + entityName + “</a:LogicalName>”;
requestXML += ” <a:Name i:nil=\”true\” />”;
requestXML += ” </b:value>”;
requestXML += ” </a:KeyValuePairOfstringanyType>”;
requestXML += ” </a:Parameters>”;
requestXML += ” <a:RequestId i:nil=\”true\” />”;
requestXML += ” <a:RequestName>” + requestName + “</a:RequestName>”;
requestXML += ” </request>”;
requestXML += ” </Execute>”;
requestXML += ” </s:Body>”;
requestXML += “</s:Envelope>”;
var req = new XMLHttpRequest();
req.open(“POST”, ServicePath, false)
req.setRequestHeader(“Accept”, “application/xml, text/xml, */*”);
req.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
req.setRequestHeader(“SOAPAction”, “http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute&#8221;);
req.send(requestXML);
}

if (req.status == 200)
{
alert(“Services Updated…”);
}
else
{
Xrm.Utility.alertDialog(req.statusText + “n” + req.responseXML.getElementsByTagName(“faultstring”)[0].textContent);
}
}
}

Call this Function in your Ribbon Customization (this triggers the Plugin). Thats it. Action is Ready..

Naren

CRM Plugin Programatically Create SharePoint Folder

Hi Guys,

I got a requirement to create Folder in SharePoint Programatically using CRM Plugins whenever a Case record is created in CRM. I have gone through so many blogs, but i was getting one or the other errors. Atlast, found a simple way to create Folders in Sharepoint and its working good too..

Note: You need to add Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime DLLs inorder to achieve this.

Also Check SP is configured with the CRM instance which you are deploying this code

This is the Plugin code:

using Microsoft.Crm.Sdk.Messages;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Net;
using SP = Microsoft.SharePoint.Client;

namespace SPDocUpload
{
public class SPCreateFolder : IPlugin
{
private IPluginExecutionContext context;
private IOrganizationServiceFactory serviceFactory;
private IOrganizationService service;
private Entity Case;

public void Execute(IServiceProvider serviceProvider)
{
this.context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
this.serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
this.service = serviceFactory.CreateOrganizationService(context.UserId);

if (context.PostEntityImages.Contains(“Target”) && context.PostEntityImages[“Target”] is Entity)
{
this.Case = (Entity)context.PostEntityImages[“Target”];
Guid CaseId = (Guid)((Entity)context.PostEntityImages[“Target”]).Id;
string title = this.Case.Attributes[“title”].ToString().Replace(” / “,”_”) + “_” + CaseId.ToString().Replace(“-“, “”); //Here I am Concatenating Case Title and GUID of the Case inorder to create an Unique SP Folder
string SharepointsiteURL = “http://samplesp:8888/&#8221;; //SharePoint Site URL
string entityDisplayName = “incident”;
NetworkCredential creds = new NetworkCredential(“username”, “password”, “domain”);

using (ClientContext clContext = new ClientContext(SharepointsiteURL))
{
clContext.Credentials = creds;

Web site = clContext.Web;
clContext.Load(site);
clContext.Load(site.Folders);

Web rootWeb = clContext.Web;
clContext.Load(rootWeb);

string sharePointURL = “incident”;

// Create a Folder in Sharepoint
Folder currentRunFolder = rootWeb.GetFolderByServerRelativeUrl(sharePointURL);
currentRunFolder.Folders.Add(title);
currentRunFolder.Update();
clContext.ExecuteQuery();
}

CreateFolderStructure(SharepointsiteURL + entityDisplayName, SharepointsiteURL + entityDisplayName + title);
CreateAndAssociateSharePointDocumentLocation(service, CaseId, title);
}
}

public static bool CreateAndAssociateSharePointDocumentLocation(IOrganizationService iService, Guid guidIncidentId, string title)
{
string url = “http://samplesp:8888/incident/&#8221; + title;  //SP Site URL including the Main Document library (“incident” in my scenario) and unique name given for SP Folder creation

Entity SPDocLocation = new Entity(“sharepointdocumentlocation”);
SPDocLocation.Attributes[“name”] = “Documents on Default Site 1”;
SPDocLocation.Attributes[“description”] = “SharePoint Document Location created for storing documents related to” + title;
SPDocLocation.Attributes[“absoluteurl”] = url;
SPDocLocation.Attributes[“regardingobjectid”] = new EntityReference(“incident”, guidIncidentId);
iService.Create(SPDocLocation);
return true;
}

private bool CreateFolderStructure(string strSharePointDocumentUrl, string strFolderUrl)
{
if (CreateFolder(strSharePointDocumentUrl))
{
return CreateFolder(strFolderUrl);
}
return false;
}

private bool CreateFolder(string strFolderUrl)
{
try
{
WebRequest request = WebRequest.Create(strFolderUrl);
request.Credentials = new NetworkCredential(“username”, “password”, “domain”);
request.Method = “MKCOL”;
WebResponse response = request.GetResponse();
response.Close();
}
catch (Exception ex)
{
// throw ex;
}
return true;
}

}
}

Regards,

Naren

CRM 2011 Plugin: One or more of the option set values for picklist are not in the range of allowed values

Today I wrote a plugin for Record Assignment scenario.

After the plugin is registered, I got the error: “One or more of the option set values for picklist are not in the range of allowed values“. I thought the error was with regards to Plugin and so, I disabled it. Now it worked well.

But I am getting this error for the first time, also I was so curious to find the cause for this. I have searched some blogs but I haven’t found anything that exactly fixes this.

I assigned a default value for the picklist that is throwing this error. Now I enabled the plugin again and tried. It worked like a Charm:-)

Cheers,

Naren

CRM 2011 Javascript checking logged-in User’s Team

Hi All,

Here is a more better way to Check logged-in User’s Team

Note: You have to download the CRM Service Toolkit and add that as a web-resource in CRM. Also call this web-resource on the form where you are calling the below Jscript

The JScript Code is:

function checkUserTeam()
{
var UserID = Xrm.Page.context.getUserId();

//FetchXML to retrieve User’s Team
var fetchXML = “<fetch version=’1.0′ output-format=’xml-platform’ mapping=’logical’ distinct=’true’>” +
“<entity name=’team’>” +
“<attribute name=’name’ />” +
“<attribute name=’businessunitid’ />” +
“<attribute name=’teamid’ />” +
“<order attribute=’name’ descending=’false’ />” +
“<link-entity name=’teammembership’ from=’teamid’ to=’teamid’ visible=’false’ intersect=’true’>” +
“<link-entity name=’systemuser’ from=’systemuserid’ to=’systemuserid’ alias=’ab’>” +
“<filter type=’and’>” +
“<condition attribute=’systemuserid’ operator=’eq’ value='”+UserID+”‘ />” +
“</filter>” +
“</link-entity>” +
“</link-entity>” +
“</entity>” +
“</fetch>”;

var fetch_detail = CrmServiceToolkit.Fetch(fetchXML);

//alert(fetch_detail.length);
if (parseInt(fetch_detail.length) > 0)
{
var Team;
for (var i = 0; i < fetch_detail.length; i++)
{
if(Team == null)
{
Team = fetch_detail[i].getValue(‘name’);
}
else //If the User is linked to Multiple Teams
{
Team = Team + “, ” + fetch_detail[i].getValue(‘name’);
}
}
//Checking Team Name(Here RM Assignment is the Team’s Name)
var rslt = Team.indexOf(‘RM Assignment’);
if(rslt != -1)
{
//Here I am enabling the field if User belongs to the Team “RM Assignment”
Xrm.Page.ui.controls.get(“new_rm”).setDisabled(false);
}
else {
Xrm.Page.ui.controls.get(“new_rm”).setDisabled(true);
}
}
}

Cheers,

Naren

CRM 2011 “Microsoft Dynamics CRM has experienced an error. Reference number for administrators or Support”

Few days back, when I tried to create a new record from related entity, it shows an error “Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support…”

I don’t have any plugins registered on the record creation. Am wondered why CRM is throwing this error. Also I have enabled Tracing and checked for error log, I couldn’t find enough details there also. I keep on thinking and at last, I have checked the relationship between two entities. There comes the error.

In detail, I have created a Custom entity and mapped it to Sales Order (1:N). When I am trying to create the Custom entity record from Sales Order, it throws the above mentioned error. Then I have checked the relationship and the fields that are mapped inside that. While creating the relationship, I have clicked “Generate Mappings” from the Actions Menu.

So all the system fields got auto-mapped. The thing here is, Sales Order have many Statuses like Active, Cancelled, Fulfilled, Invoiced, Submitted, and the Custom entities will be having only Active, Inactive Statuses. This created the problem and I removed this field mapping from the relationship. Now it started working like a charm.

Cheers,

Naren

CRM 2013 Calculate Totals from Subgrid

Hi Tech’ies,

I got a requirement to calculate the Total Value(a decimal field) from all the records inside a Subgrid (N:N Relationship) in CRM’13. I was thinking to do this, because CRM 2013 won’t support some functions such as document.getElementById but CRM 2011 will support this.

But, I tried this way and it worked well.

 

function getTotal(){
setTimeout(calcCostoTotal, 2000);
}

function calcCostoTotal() {

var grid = document.getElementById(‘CasualStaffForm’); //Name of the Subgrid
var ids = grid.control.get_allRecordIds();
var sum = 0.00;
var cellValue;

for(i = 0; i < ids.length; i++) {

var cellValue = grid.control.getCellValue(‘new_total’,ids[i]);

//new_total is the decimal field in related entity(record inside subgrid)

var number = Number(cellValue.replace(/[^0-9\.]+/g,””));
sum = sum + number;
}

alert(sum);

}

 

Cheers,

Naren

CRM 2011 JavaScript passing parameter to SSRS Reports

I had a requirement to generate report from the ribbon button, and my report takes the record’s GUID as its parameter.

Passing parameters to SSRS reports is nothing but, we need to provide the Record’s GUID, Entity type code and Parameter value as the URL. So I have written a Jscript to get GUID value of the record. My Report URL is like:

window.open(“/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=” +RdlName+ “&id=%7b” +ReportID+ “%7d&records=” +ID+ “&recordstype=” +ETC+ “&p:Parameter=” +ID + “”);

“RdlName” denotes the name of RDL that you created (Open the SSRS Report Project and copy the rdl name from there).

“ReportID” is the GUID of that report

“ETC” denotes the Entity Type Code

“Parameter” is nothing but the parameter name that is used in reports (Open the SSRS Report Project and copy the parameter name from there)

“ID” denotes the parameter value. Here I have passed the Record’s GUID as a parameter. You can fetch the parameter value in Jscript and use that here.

Below is the Script that I have written for opening Report:

function viewReport() {

var ID = Xrm.Page.data.entity.getId();

window.open(“/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=” +RdlName+ “&id=%7b” +ReportID+ “%7d&records=” + ID + “&recordstype=” +ETC+ “&p:Parameter=” +ID + “”);

}

Note: In my case, both Record ID and Parameter are same, as I am passing Record GUID as parameter value.

Cheers,

Naren

The type or namespace name ‘xrm’ does not exist in the namespace ‘Microsoft’

Hi everyone,,

Today, while writing a Console application, I came up with an error saying: The type or namespace name ‘xrm’ does not exist in the namespace ‘Microsoft’.

Even-though I have added all the referencing dll’s from the SDK’s bin folder, I got this error.

Image

I was little bit confused. After sometime, I got the resolution for this error by just:

Right Clicking on the Project -> Properties -> Application and setting the Target Framework to .NET Framework 4.

By default, it was set to .NET Framework 4 Client Profile. It should be set to Client Profile only for WCF and other Windows Forms applications.  So, I just changed it to .NET Framework 4.

Image

.NET Framework Client Profile is nothing but the subset of .NET Framework with some features contained in it.

The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications. It provides functionality for most client applications, including Windows Presentation Foundation (WPF), Windows Forms, Windows Communication Foundation (WCF), and ClickOnce features. This enables faster deployment and a smaller install package for applications that target the .NET Framework 4 Client Profile. To know more, Click here.

Cheers,

Naren

CRM 2011 Invalid Date/Time in the Filtered Lookup

Filtering the Lookup based upon any condition is a common approach. I had a scenario to filter the records based on date (Accounts that are having an end date “on or after” today’s date are to be displayed in the lookup). After downloaded the fetchXML, I found that fetchXML is considering the date format as “yyyy-MM-DD”.

CRM date field won’t consider this date format. By default, it will be in the “DD-MM-yyyy” format.  If I write fetchXML without formatting the date, it displays an error stating:

Image

This is the fetchXML that I have downloaded from Account entity:

<fetch version=“1.0” output-format=“xml-platform” mapping=“logical” distinct=“false”>

<entity name=“account”>

<attribute name=“name” />

<attribute name=“primarycontactid” />

<attribute name=“emailaddress1” />

<attribute name=“address1_addresstypecode” />

<attribute name=“new_date” />

<attribute name=“accountid” />

<order attribute=“name” descending=“false” />

<filter type=“and”>

<condition attribute=“address1_addresstypecode” operator=“eq” value=”1” />

      <condition attribute=“new_date” operator=“on-or-after” value= “2013-08-29” />

</filter>

</entity>

</fetch>

Henceforth, I should format the date as per the date in fetchXML. (i.e.), I need to consider the format as “yyyy-MM-DD” instead “DD-MM-yyyy”. So, I just included this code in the Script:

var today = new Date();

var futureDate = new Date(today.setDate(today.getDate()));

var dtFrmtd = futureDate.format(“yyyy-MM-dd”);

 

Now, the complete code is:

function filterLookup()

{

var addr = Xrm.Page.getAttribute(“address1_addresstypecode”).getValue();

var today = new Date();

var futureDate = new Date(today.setDate(today.getDate()));

var dtFrmtd = futureDate.format(“yyyy-MM-dd”);

var viewId = “{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}”;

var entityName = “account”;

var viewDisplayName = “Accounts with the same Address type”;

var fetchXml = “<fetch version=’1.0′ output-format=’xml-platform’ mapping=’logical’ distinct=’false’>”+

“<entity name=’account’>”+

“<attribute name=’name’ />”+

“<attribute name=’primarycontactid’ />”+

“<attribute name=’emailaddress1′ />”+

“<attribute name=’address1_addresstypecode’ />”+

“<attribute name=’new_date’ />”+

“<attribute name=’accountid’ />”+

“<order attribute=’name’ descending=’false’ />”+

“<filter type=’and’>”+

“<condition attribute=’address1_addresstypecode’ operator=’eq’ value='”  + addr + “‘ />”+

“<condition attribute=’new_date’ operator=’on-or-after’ value='”  +dtFrmtd+ “‘ />”+

“</filter>”+

“</entity>”+

“</fetch>”;

var layoutXml = “<grid name=’resultset’ object=’1′ jump=’name’ select=’1′ icon=’1′ preview=’1′>” +

“<row name=’result’ id=’accountid’>” +

“<cell name=’name’ width=’300′ />” +

“<cell name=’primarycontactid’ width=’150′ />” +

“<cell name=’telephone1′ width=’100′ />” +

“</row>” +

“</grid>”;

Xrm.Page.getControl(“parentcustomerid”).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

}

That’s it. Now, It worked Well.

Cheers,

Naren