Archive for the ‘Uncategorized’ Category

Behavior of Roll-Up and Calculated Fields in Quick view Form

July 1, 2015 2 comments

1. Roll-up field will not show value in a quick view form. It will be always empty

2. Calculated field will show  right value in a Quick view form

I had requirement to show calculated and roll-up fields of an lookup record in a form. I thought using quick view form it will be 5 minutes of work. But for my surprise quickview form shows all the fields of an lookup record with values except roll-up fields.  I thought it might be because of  lookup record has null value in roll-up field. But that’s not the case  when i opened lookup record it shows value in the roll-up field.

It seems like product bug when you add roll-up field in a quickview form it never  shows value.

So don’t use roll-up field in a Quick view form, You can add Calculated field in a quick view form and it works with out any issue.

Categories: Uncategorized

Change Label Position in Quick View form

February 7, 2015 Leave a comment

In any entity Main Form we can customize the Field label position for the section  Either Side or Top. For example if you want to show label of the field in the top you can do this by selecting the section properties and in format tab under “Field Label Position” you can choose top.


Same way you can change Field label position to “Side” to display label in the left side of the field. When we form with fields and  Quick view form, where all form Field Label position is set to Top ,

Still quick view form shows filed label in the left and it does not look good in the form. If you try to change the quick view form Field label position there is no option in the UI customization section.

To change the Quick view form “Field Label Position” to Top  or vise versa you can follow the below steps

1. Create new solution  and the quick view form entity to the solution. ( Eg : For Contact Quick view  , Add contact entity to the solution )

2.Export the solution and unzip the solution.

3.Copy the Customization.xml from the zip fle and open the customization.xml in any text editor

4. Find the quick view form in the customization XMl, in the form locate the <tabs><sections> tag and corresponding <section> tag that you want to change Field Label Position. ( For example Information section in contact Quick view form)

5. in the section xml tag add celllabelposition=”Top” attribute to show label in top of the field and celllabelposition=”Left” to show label in the left. Showing label in left is the default behavior.


6.After adding this attribute to the Xml save the customization.xml and place this xml file back to solution and import into system and publish it.

Here is the final result  where Filed labels placed in top of the field in Quick view form


Here is sample customization.Xml file that i have used to change ” Contact quick view” form to show label in the top

<forms type=”quick”>
<form hasmargin=”false” shownavigationbar=”false”>
<ancestor id=”{bdb0ae1c-32fa-4374-b637-8dafe107bc44}” />
<tabs showlabels=”false”>
<tab name=”general” verticallayout=”true” id=”{6fd9013a-2c88-4593-b364-c9f21e572640}” IsUserDefined=”0″>
<label description=”General” languagecode=”1033″ />
<column width=”100%”>
<section name=”information” id=”{a9d2c4bb-9863-4712-b13c-f27c88331597}” IsUserDefined=”0″ showlabel=”false”
showbar=”false” celllabelposition=”Top”>


If it’s a default system quick view form system may not export the quick view form as part of the solution. In order to system export the quick view form, add any field to the quick  view form and save and publish it . If you export the solution now , system will export the quick view form as part of the solution.

Categories: Uncategorized

MS crm 2013/2015 connecting to Power BI

February 5, 2015 Leave a comment

Below are the steps to connect CRM ODATA to the Power BI in excel.

1. Make sure you have Power query add-on installed for your excel.

2.If you already have Power query installed you will see new tab in excel “Power Query”


3.To connect CRM in excel click on power query tab and in the other sources


4.CLick on other Odata Feed

5.Once you click on OData feed it will prompt to enter Odata feed URL .You can get CRM ODATA URL by going to

settings->Customization->Developer Resources ->Organization Data Service


6.copy the odata url and paste in the OData feed url sceen


7.Once you click on ok , it will pormpt to sign in. Clik on Organizational account


8.Enter the credential of CRM to login and save the connection .


9.Once you save the connection, it will load all the entities avilable in your crm and you can choose which entity record data you want to load into excel.Once data is loaded you can play around with BI query to make it better.

Categories: Uncategorized

Unlock fulfilled order by mistake for edit

January 27, 2015 Leave a comment

Lot of times i see in community forum people asking how to unlock order that is fulfilled by mistake. I come across same kind of requests from our order processing team in the past.

To unlock an order that is fullfilled by mistake follow below steps.

1.Create a ondemand workflow on order entity.

2. Add step -> Change status

3.By default it will show order entity in the drop down and in the status drop down choose any one of the item under Active -> New or pending .

4.Activate the workflow.

5.Open the order that you want to unclock and click on run workflow and choose the newly created workflow

6.Once workflow status change to success , refresh the order record and you will see order is unlocked for edit now.


Categories: Uncategorized

Tip : Save Read-only field values when value set by Business Rule

November 4, 2014 Leave a comment

We all know when field is set to read-only  on the form it won’t be saved until we set SumbitMode = “always” . For example if you populate value of the field2 ( Read-only)  based on  field1 on the form  using Business rule  when you save the record,  field2 value won’t be saved as it’s a read-only field on the form.

To fix this issue  add field2 to the form one more time with “Show by dafault” unchecked and as read-write.

Basically we have Field2 twice in the form , one field set to read-only ( Field Read-only checked) and “Visible by default” checked . Other one is read-write ( Field Read-only Unchecked)  and “Visible by default” unchecked ( not visible in the form). When we populate Field2 value using Business rule it sets the Value on both the instance of the field2. As one instance of the field is read-write,  system automatically saves the field value.


1. Field  “Test1”  added twice in the form, one is read-only and set “Visible by Default” checked  , other one set to Read-write and “Visible by default ” unchecked


2. Business Rule to Update Test1″ field value whenever email changes.


3.Form when you create new record or existing record




4. Field “Test1” value saved even though it set to read-only on the form.



Categories: Uncategorized

MS CRM 2011/2013 : Polymorphic Data Rollup Workflow Activity ( 1:N )

October 28, 2014 3 comments

Has we come across lot of times to rollup data from all child records to Parent record ( N:1) , created generic Data Rollup workflow activity to solve this problem.

Scott Polymorphic Input Parameter helped to achieve this.


The logic of this workflow is very simple.

It  takes following parameters as Input in the Workflow activity and rollup’s the data from child records to Parent record.

1. Dynamics Record URL ( Parent Record)

2. Logical Name of the Parent Entity

3.Lookup Attribute name of the Parent entity in child entity

4. Include only child records with set of statuses

5.Include only child records with set of Status reasons.

6. Parent and child Attribute names to rollup data  ex :  {ParentAttribute1 :  ChildAttribute1},{ParentAttribute2:ChildAttribute2}

Each pair represents the rollup filed in the parent record and child record. You can add as many rollup fields you want as long as Parent field name is unique. I mean parent attribute name should not duplicate.

You can use this workflow activity in Back-ground process as well on Real-time workflow to Rollup Sum into parent record immediately.

At present this workflow only supports Sum of fields and updating parent record with the same.

Supported data type for rollup attributes  are

1. Whole Number , Decimal , and Float

2. Currency.

You can find managed solution ,Dll and Source code in Codeplex



Generate PDF from report in CRM online 2013

October 17, 2014 Leave a comment

I saw good post from crm community about how to generate pdf from the report and send it via email

copied from the community for my reference..

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”&gt;
<html xmlns=””&gt;
<script src=””></script&gt;
<script type=”text/javascript”>
if (typeof (SDK) == “undefined”)
{ SDK = { __namespace: true }; }
SDK.JScriptRESTDataOperations = {
_context: function () {

if (typeof GetGlobalContext != “undefined”)
{ return GetGlobalContext(); }
else {
if (typeof Xrm != “undefined”) {
return Xrm.Page.context;
else { return new Error(“Context is not available.”); }
_getServerUrl: function () {
var serverUrl = this._context().getServerUrl()
if (serverUrl.match(/\/$/)) {
serverUrl = serverUrl.substring(0, serverUrl.length – 1);
return serverUrl;
_ODataPath: function () {
return this._getServerUrl() + “/XRMServices/2011/OrganizationData.svc/”;
_errorHandler: function (req) {
return new Error(“Error : ” +
req.status + “: ” +
req.statusText + “: ” +
_dateReviver: function (key, value) {
var a;
if (typeof value === ‘string’) {
a = /Date\(([-+]?\d+)\)/.exec(value);
if (a) {
return new Date(parseInt(value.replace(“/Date(“, “”).replace(“)/”, “”), 10));
return value;
Create: function (object, type, successCallback, errorCallback) {
var req = new XMLHttpRequest();“POST”, this._ODataPath() + type + “Set”, true);
req.setRequestHeader(“Accept”, “application/json”);
req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 201) {
successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d);
else {
Retrieve: function (id, type, successCallback, errorCallback) {
var req = new XMLHttpRequest();“GET”, this._ODataPath() + type + “Set(guid'” + id + “‘)”, true);
req.setRequestHeader(“Accept”, “application/json”);
req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 200) {
successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d);
else {
Update: function (id, object, type, successCallback, errorCallback) {
var req = new XMLHttpRequest();“POST”, this._ODataPath() + type + “Set(guid'” + id + “‘)”, true);
req.setRequestHeader(“Accept”, “application/json”);
req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
req.setRequestHeader(“X-HTTP-Method”, “MERGE”);
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 204 || this.status == 1223) {
else {
Delete: function (id, type, successCallback, errorCallback) {
var req = new XMLHttpRequest();“POST”, this._ODataPath() + type + “Set(guid'” + id + “‘)”, true);
req.setRequestHeader(“Accept”, “application/json”);
req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
req.setRequestHeader(“X-HTTP-Method”, “DELETE”);
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 204 || this.status == 1223) {
else {

RetrieveMultiple: function (type, filter, successCallback, errorCallback) {

if (filter != null) {
filter = “?” + filter;
else { filter = “”; }

var req = new XMLHttpRequest();“GET”, this._ODataPath() + type + “Set” + filter, true);
req.setRequestHeader(“Accept”, “application/json”);
req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8″);
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 200) {
successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d.results);
else {


__namespace: true
<script type=”text/javascript”>
//Create Email and link it with Order as Regarding field
var Xrm;
var email = new Object();
var ownerID = “”;
var CustomerId = “”;
if (window.opener) { Xrm = window.opener.Xrm; }
else if (window.parent) { Xrm = window.parent.Xrm; }

//Get ownerid who send email of quotation to customer
function GetOwnerID() {
var owner = Xrm.Page.getAttribute(“ownerid”).getValue();
ownerID = owner[0].id;
var ownerName = owner[0].name;
var entityType = owner[0].entityType;

//Get customerid who receive email of quotation from owner
function GetToEmailGUID() {
var Customer = Xrm.Page.getAttribute(‘customerid’).getValue();
CustomerId = Customer[0].id;
var CustomerName = Customer[0].name;
var entityType = Customer[0].entityType;

//if CustomerId is type of “Account” then get Primary Contact id of that account
if (entityType == “account”) {
var contact = Xrm.Page.getAttribute(“customerid”).getValue();

if (contact === null) return;

var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + “/XRMServices/2011/OrganizationData.svc/AccountSet(guid'” + contact[0].id + “‘)?$select=PrimaryContactId”;

var req = new XMLHttpRequest();“GET”, oDataSelect, false);
req.setRequestHeader(“Accept”, “application/json”);
req.setRequestHeader(“Content-Type”, “application/json;charset=utf-8”);
req.onreadystatechange = function () {
if (req.readyState === 4) {
if (req.status === 200) {
var retrieved = JSON.parse(req.responseText).d;
CustomerId = retrieved.PrimaryContactId.Id;
else {

function CreateEmail() {
email.Subject = “Email with Report Attachment”;

//Set The current order as the Regarding object
email.RegardingObjectId = {

Id:,    //Get the current entity Id , here OrderId
LogicalName: the current entity name, here it will be “salesOrder”

//Create Email Activity
SDK.JScriptRESTDataOperations.Create(email, “Email”, EmailCallBack, function (error) { alert(error.message); });

// Email Call Back function

function EmailCallBack(result) {
email = result; // Set the email to result to use it later in email attachment for retrieving activity Id
var activityPartyFrom = new Object();

// Set the From party of the ActivityParty to relate an entity with Email From field
activityPartyFrom.PartyId = {
Id: CustomerId, //”79EBDD26-FDBE-E311-8986-D89D6765B238″,  // id of entity you want to associate this activity with.
LogicalName: “contact”
// Set the “activity” of the ActivityParty

activityPartyFrom.ActivityId = {
Id: result.ActivityId,
LogicalName: “email”

// Now set the participation type that describes the role of the party on the activity).

activityPartyFrom.ParticipationTypeMask = { Value: 2 }; // 2 means ToRecipients

// Create the from ActivityParty for the email

SDK.JScriptRESTDataOperations.Create(activityPartyFrom, “ActivityParty”, ActivityPartyFromCallBack, function (error) { alert(error.message); });

var activityPartyTo = new Object();

// Set the From party of the ActivityParty to relate an entity with Email From field
activityPartyTo.PartyId = {
Id: ownerID, //”79EBDD26-FDBE-E311-8986-D89D6765B238″,  // id of entity you want to associate this activity with.
LogicalName: “systemuser”

// Set the “activity” of the ActivityParty
activityPartyTo.ActivityId = {
Id: result.ActivityId,
LogicalName: “email”

// Now set the participation type that describes the role of the party on the activity).
activityPartyTo.ParticipationTypeMask = { Value: 1 }; // 1 means Sender

// Create the from ActivityParty

SDK.JScriptRESTDataOperations.Create(activityPartyTo, “ActivityParty”, ActivityPartyToCallBack, function (error) { alert(error.message); });

//ActivityParty From Callback

function ActivityPartyFromCallBack(result) {

//ActivityParty To Callback

function ActivityPartyToCallBack(result) {
//Create attachment for the created email

function CreateEmailAttachment() {
//get reporting session and use the params to convert a report in PDF

var params = getReportingSession();

//Email attachment parameters

var activitymimeattachment = Object();
activitymimeattachment.ObjectId = Object();
activitymimeattachment.ObjectId.LogicalName = “email”;
activitymimeattachment.ObjectId.Id = email.ActivityId;
activitymimeattachment.ObjectTypeCode = “email”,
activitymimeattachment.Subject = “File Attachment”;
activitymimeattachment.Body = encodePdf(params);
activitymimeattachment.FileName = “Report.pdf”;
activitymimeattachment.MimeType = “application/pdf”;

//Attachment call
SDK.JScriptRESTDataOperations.Create(activitymimeattachment, “ActivityMimeAttachment”, ActivityMimeAttachmentCallBack, function (error) { alert(error.message); });

//ActivityMimeAttachment CallBack function

function ActivityMimeAttachmentCallBack(result) {
var features = “location=no,menubar=no,status=no,toolbar=no,resizable=yes”;
var width = “800px”;
var height = “600px”; + “main.aspx?etc=” + 4202 + “&pagetype=entityrecord&id=” + email.ActivityId, “_blank”, features);

// To open window which works in outlook and IE both
//openStdWin(Xrm.Page.context.getServerUrl() + “main.aspx?etc=” + 4202 + “&pagetype=entityrecord&id=” + email.ActivityId, “_blank”, width, height, features);

//This method will get the reportId based on a report name that will be used in            getReportingSession() function

function GetReportId(reportName) {
var oDataSetName = “ReportSet”;
var columns = “ReportId”;
var filter = “Name eq ‘” + reportName + “‘”;
retrieveMultiple(oDataSetName, columns, filter, onSuccess);

function retrieveMultiple(odataSetName, select, filter, successCallback) {

var serverUrl = Xrm.Page.context.getServerUrl();
var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;
var odataUri = serverUrl + ODATA_ENDPOINT + “/” + odataSetName + “?”;

if (select) {
odataUri += “$select=” + select + “&”;

if (filter) {
odataUri += “$filter=” + filter;

type: “GET”,
contentType: “application/json; charset=utf-8”,
datatype: “json”,
url: odataUri,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);


success: function (data) {
if (successCallback) {
if (data && data.d && data.d.results) {
else if (data && data.d) {
else {
error: function (XmlHttpRequest, errorThrown) {
if (XmlHttpRequest && XmlHttpRequest.responseText) {
alert(“Error while retrieval ; Error – ” + XmlHttpRequest.responseText);



function onSuccess(data) {
reportId = data[0].ReportId.replace(‘{‘, “).replace(‘}’, “);
CreateEmailAttachment(); // Create Email Attachment

//Gets the report contents

function getReportingSession() {
var pth = Xrm.Page.context.getServerUrl() + “/CRMReports/rsviewer/reportviewer.aspx”;
var retrieveEntityReq = new XMLHttpRequest();
var Id =;
var quotationGUID = Id.replace(‘{‘, “”); //set this to selected quotation GUID
quotationGUID = quotationGUID.replace(‘}’, “”);

var reportName = “Quotation_Report”; //set this to the report you are trying to download
var reportID = “7C39D18F-1DC6-E311-8986-D89D6765B238”; //set this to the guid of the report you are trying to download
var rptPathString = “”; //set this to the CRMF_Filtered parameter
var strParameterXML = “<fetch version=’1.0′ output-format=’xml-platform’ mapping=’logical’ distinct=’false’><entity name=’quote’><all-attributes /><filter type=’and’><condition attribute=’quoteid’ operator=’eq’ uitype=’quote’ value='” + quotationGUID + “‘ /> </filter></entity></fetch>”;“POST”, pth, false);
retrieveEntityReq.setRequestHeader(“Accept”, “*/*”);
retrieveEntityReq.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);

rptPathString = “id=%7B” + reportID + “%7D&uniquename=” + Xrm.Page.context.getOrgUniqueName() + “&iscustomreport=true&reportnameonsrs=&reportName=” +
reportName + “&isScheduledReport=false&p:CRMAF_Filteredquote=” + strParameterXML;
//remove the part starting from &p:salesorderid if your report has no parameters


var x = retrieveEntityReq.responseText.indexOf(“ReportSession=”);
var ret = new Array();
ret[0] = retrieveEntityReq.responseText.substr(x + 14, retrieveEntityReq.responseText.indexOf(“&”, x) – x – 14); //the session id
x = retrieveEntityReq.responseText.indexOf(“ControlID=”);
ret[1] = retrieveEntityReq.responseText.substr(x + 10, retrieveEntityReq.responseText.indexOf(“&”, x) – x – 10); //the control id

return ret;
var bdy = new Array();
var bdyLen = 0;
function concat2Bdy(x) {
bdy[bdyLen] = x;
function encodePdf(params) {

bdy = new Array();
bdyLen = 0;

var retrieveEntityReq = new XMLHttpRequest();
var pth = Xrm.Page.context.getServerUrl() + “/Reserved.ReportViewerWebControl.axd?ReportSession=” + params[0] +
“&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=” + params[1] +
“&OpType=Export&FileName=Public&ContentDisposition=OnlyHtmlInline&Format=PDF”;“GET”, pth, false);
retrieveEntityReq.setRequestHeader(“Accept”, “*/*”);

return encode64(bdy);


var StringMaker = function () { = [];
this.length = 0;
this.append = function (s) {;
this.length += s.length;

this.prepend = function (s) {;
this.length += s.length;

this.toString = function () {

var keyStr = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=”;

function encode64(input) {
var output = new StringMaker();
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;

while (i < input.length) {
chr1 = input[i++];
chr2 = input[i++];
chr3 = input[i++];

enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;

if (isNaN(chr2)) {
enc3 = enc4 = 64;

} else if (isNaN(chr3)) {
enc4 = 64;

output.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));

return output.toString();

<script type=”text/vbscript”>

Function BinaryToArray(Binary)

Dim i

ReDim byteArray(LenB(Binary))

For i = 1 To LenB(Binary)

byteArray(i-1) = AscB(MidB(Binary, i, 1))

concat2Bdy(AscB(MidB(Binary, i, 1)))


BinaryToArray = byteArray

End Function

<input type=”button” onclick=”CreateEmail();” value=”Attach Report” />

Categories: Uncategorized