Thursday, November 12, 2015

Retrieve Product Properties using JavaScript in CRM 2015

Hi,

Today we got a requirement to show Product Properties related to Opportunity Product in a HTML Webresource.

Here is the JavaScript code to read Product Properties.


  function getProperties() {
            var jsonResult = null;
            var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
            var retrieveRecordsReq = new XMLHttpRequest();
            var oDataPath = "";
            var entityName = "DynamicPropertyInstance";
            var entityNameField = "*";
            oDataPath = Xrm.Page.context.getClientUrl() + ODATA_ENDPOINT + "/" + entityName + "Set?$select=*&$filter=RegardingObjectId/Id eq guid'" + vOpportunityProductId + "'";
            retrieveRecordsReq.open('GET', oDataPath, false);
            retrieveRecordsReq.setRequestHeader("Accept", "application/json");
            retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8")
            retrieveRecordsReq.send(null);
            var retrievedData = JSON.parse(retrieveRecordsReq.responseText).d;
            if (retrievedData != null && retrievedData != undefined && retrievedData.results != null) {
                jsonResult = retrievedData.results;
            }
             return jsonResult;
        }
Hope this helps.

--

Happy CRM'ing
Gopinath

Wednesday, November 11, 2015

The column heading cannot be empty in CRM 2013/2015

Hi,

Today I received the below error when I was importing some records to CRM using OOB import.

"The column heading cannot be empty".

Here are the steps to resolve.

1) Open the CSV file in notepad.
2) Check for a comma at the end of each row.
3) To make the things much easier, close the Notepad and open the same in Microsoft Excel.
4) Remove the blank column by selecting and deleting.
5) Save the file.
6) Open the file in Notepad again and check to make sure the comma at the end of each row has removed.
7) Import the file. This time, you won't see any error.

Hope this helps.

--
Happy CRM'ing
Gopinath

How to get the records count per table from SQL Server Database?

Hi,

I have started working on Data Migration work. So, started knowing more on SQL Server, Tables, Database Sizes and etc..

Today, I found the way to know the Records count per table and size of each table in the Database.
Here are the steps to follow for getting the details.

1) Logon to SQL Server Management Studio
2) Right-click on the database which you want to know the details.
3) Select Reports -> Standard Reports -> Disk Usage by Table.

4) A report will be loaded in a new tab. This might take a couple of seconds depending on the size of the database.
5) You can export the report to Excel, PDF and Word and perform your analysis on it.
Note : This procedure can be applied for any database. As CRM Database is my favorite, I have taken that as a sample.

Hope this helps.

--
Happy Querying.

Gopinath 

How to check the database size in SQL Server?

Hi,
 
Today, I got know the size of the database. But unfortunately I could not get the correct database size on the file system until I take the back up.
 
Select the database, right click and click on properties.
 
 
In the above image, the size shown 460.81 MB is sum of Data and Log files. It doesn't mean that real size of the database would be the same.
 
I have taken the back up of the database and on the file system the size mentioned was 262 MB.
 
Space Available 90.03 MB is the space that is still available to fill up. Once this space is utilized then SQL Server will allocates new Data space and Log space as per the growth rate set.
 
Use the following query to see the size of Log files and data files individually.
 
SELECT DB_NAME(database_id) AS DatabaseName,
Name AS Logical_Name,
Physical_Name, (size*8)/1024 SizeMB
FROM sys.master_files
WHERE DB_NAME(database_id) = 'DB_NAME'

Output
351 + 109 = 460 MB.
 
Hope this helps.
 
--
Cheers

Gopinath 

Tuesday, November 10, 2015

Security Roles Assigned to User in CRM

Hi,

Today I have been asked by one of our clients is there any way to find the security privileges that are assigned to some users in CRM Organization.

Yes, we can see. Dynamics CRM out of the box comes with a set of reports. You will find a report named "User Summary".

If you run the report, you will see table with User's information. I cannot show you the output of the report here. :)

Hope this helps.

--
Happy CRM'ing

Gopinath

Monday, November 9, 2015

Double Versus Decimal in C#

Double is useful for scientific computations (such as computing spatial coordinates). Decimal is useful for financial computations and values that are “man-made” rather than the result of real-world measurements. Here’s a summary of the differences.
  

CategoryDoubleDecimal
Internal RepresentationBase 2 Base 10
Decimal Precision15-16 Significant Figures28-29 Significant figures
Range±(~10−324 to ~10308) ±(~10−28 to ~1028) 
Special Values+0, −0, +∞, −∞, and NaNNone 
SpeedNative to processor Non-native to processor
(about 10 times slower than double)

Most business applications should probably be using decimal rather than float or double. Our thumb rule should be manmade values such as currency are usually better represented with decimal floating point.
 
Hope this helps.
 
--
Happy Coding
Gopinath

 

Sunday, November 8, 2015

How to check Array contains an Item in JavaScript?

Hi,
 
Here is the JavaScript  code to check Array contains an item in JavaScript.
 
var vArrValues = ["1", "2", "3", "4"];

// Check Array Contains Values
Array.prototype.contains = function (element) {
     return this.indexOf(element) > -1;
};

function CheckArrayContaintsValue(vValue) {
    if (vArrValues.contains(vValue)) {
            return true;
    }
    else {
       return false;
     }
}

CheckArrayContaintsValue("1"); // Returns True
CheckArrayContaintsValue("5"); // Returns False
 
Hope this helps.
 
--
Happy Coding.
Gopinath

Copy/ Create Views in Dynamics CRM 2011/2013/2015

Hi,

Most of the times we get the requirement to create views as same as the existing views and some of the filter conditions and columns.

Creating views is always tedious job and time-consuming process. As we all know, Dynamics CRM is always smart.

We can quickly copy an existing view to use as a starting point for a new view. This can be a big time-saver if you have a complex view that you need to create a small variation of.

To do this,
1) Just navigate to the list of views for an entit
2) Open the view you want to copy
3) Click the Save As button in the menu bar.
 4) Enter a new name for the view and it will be saved as a copy of the original.
 


5) You will see a new view created.

Hope this helps.

--
Happy CRM'ing
Gopinath

Saturday, November 7, 2015

1:N and N:1 relationships in Dynamics CRM

There are the types of relationships that we will be creating most frequently in Dynamics CRM.
 
1:N - The relationship between Contact and Asset is a typical 1:N relationship. Each contact may have many different assets associated to them.
 
N:1 - If we see the same relationship from the Asset entity, then the relationship back to Contacts can be said to be N:1. In simple words, many assets are related back to a single contact.
 
For implementing above example in Dynamics CRM, we should create a Contact Look up attribute on Asset entity.
 
Hope this helps.
--
Happy CRM'ing

Gopinath

Lead and Opportunity in Dynamics CRM 2011/2013/2015

Hi,

Here are some basic things related to Lead and Opportunity in CRM.

Leads
Leads are records that you have not yet qualified as desirable prospects for your organization. For example, if someone visits your Web site and submits a “contact us” form, your organization may want to follow up and qualify them. Once qualified, a lead is converted into an account, a contact, and possibly an opportunity. Leads that are disqualified are kept in the database for reporting purposes but are otherwise hidden from standard views. Depending on your situation, you may find that your organization makes heavy usage of leads or does not need to use leads at all. Organizations that spend a lot of time trying to filter out unqualified leads (those that they do not wish to do business with) typically find that leads are an important part of CRM. Organizations that have a captive audience of qualified leads and customers (such as a public utility) may not need to use leads at all.

Opportunities
Opportunities are potential transactions that your organization may engage in with a targeted customer. They are linked to the customer (an account or contact) to which they are related.

Hope this helps.

--
Happy CRM'ing
Gopinath

Thursday, November 5, 2015

Retrieve Option Set text from CRM 2011/2013/2015 in JavaScript

Hi,
 
Today I got a requirement to write JavaScript code to get text of the option set value and perform some business validations.
 
Its really pretty simple to get the option set text from the particular entity and attribute.
 
We just need to add SDK.Metadata.js reference. This can found under (SDK\SampleCode\JS\SOAPForJScript\SOAPForJScript\Scripts) and use the below code.

function GetOptionSetText(EntityLogicalName, AttributeLogicalName) {
    SDK.Metadata.RetrieveAttribute(EntityLogicalName, AttributeLogicalName, "00000000-0000-0000-0000-000000000000", true,
       function (result) {
            for (var i = 0; i < result.OptionSet.Options.length; i++) {
                var text = result.OptionSet.Options[i].Label.LocalizedLabels[0].Label;
                var value = result.OptionSet.Options[i].Value;
            }
        },
        function (error) { }
    );
}

Hope this helps.

--
Happy CRM'ing
Gopinath

Wednesday, November 4, 2015

Type-Cast oData Service Datetime field in CRM 2011/2013/2015

Hi,

When you retrieve CRM date time values using oData Service from CRM, you will get the date in different format as below which we cannot set to Date field.
 
Here is the way to type cast it.
 
var vDate = jsonResult[0].new_date;
vDate = vDate.replace("/Date(", "");
vDate = vDate.replace(")/", "");
var dateValue = new Date(parseInt(vDate, 10));

Hope this helps.
 
--
Happy Coding

Gopinath

Get Difference between two dates in JavaScript

Hi,

Dealing with dates will always dicey. Most of the times when we calculate difference between two dates we don't consider a Daylight saving change.

In this case, the date on which day light saving change happens will have a duration in milliseconds which != 1000*60*60*24, so the typical calculation will fail.

A more accurate way to get the number of days between two JavaScript dates can be written as follows:

// date1 and date2 are javascript Date objects
function dateDiffInDays(date1, date2) {
    var vInt_MS_PER_DAY = 1000 * 60 * 60 * 24;
    // Discard the time and time-zone information.
    var utc1 = Date.UTC(date1.getFullYear(), date1.getMonth(), date1.getDate());
    var utc2 = Date.UTC(date2.getFullYear(), date2.getMonth(), date2.getDate());
    return Math.floor((utc2 - utc1) / vInt_MS_PER_DAY);
}

Hope this helps.

--
Happy Coding
Gopinath


 

Monday, November 2, 2015

Get Option Set String from CRM 2011/2013/2015 in C#

Hi,

Most of the times, CRM developer in CRM goes to check Option Set value only finds out the value as integer.

At times, we get a requirement to get string value associated with the integer.  For doing this, we write a metadata call and as we all know metadata calls are more time consuming.

As always, CRM is smart just we need to find the correct approach.

When we retrieve the entity, we can always the string of the option set by using the following line.

string strOptionSetText = objEntity.FormattedValues["<OptionSetSchemaName>"];
Hope this helps.
--
Happy CRM'ing

Gopinath 

How to check GUIDs are equal in JavaScript

Hi,

In CRM, at times we get requirement to check two GUID's are equal or not.

Here is the JavaScript code to check two GUID's are equal.

function GuidsAreEqual(guid1, guid2) {
    var isEqual = false;
    if (guid1 == null || guid2 == null) {
       isEqual = false;
    }
    else {
        isEqual = (guid1.replace(/[{}]/g, "").toLowerCase() == guid2.replace(/[{}]/g, "").toLowerCase());
    }
    return isEqual;
}
Hope this helps.

--
Happy CRM'ing

Gopinath

How to generate a random unique 5 digit number in C#

Hi,
 
Here is the way to generate 5 digit random unique number.
 
Random objRandom = new Random();
int intValue = objRandom.Next(10000, 99999);
 
The number 10000, 99999 specifies the range

For example - If you want generate 6 digit random number, just increase the range to 100000, 999999.
 
Hope this helps.
 
--
Happy Coding
Gopinath

Business Process Stage Change and Stage Select Events in CRM 2015

Hi,

Sometimes we get a requirement to do some operations on the business process stage change or on the select of the stage. This can be done by the following way.

We have two new events addOnStageChange and addOnStageSelected.

Just attach a function to theses event on the load of the form.

function onLoad() {
    Xrm.Page.data.process.addOnStageChange(onStageChangeEvent);
    Xrm.Page.data.process.addOnStageSelected(onStageSelectEvent);
}

// Stage Change Event
function onStageChangeEvent(eventArgs) {
    alert("I am Stage Change Event");
}

// Stage Select Event
function onStageSelectEvent(eventArgs) {
    alert("I am Stage Select Event");
}

Here is the output.
 


Hope this helps.

--
Happy CRM'ing

Gopinath