Wednesday, March 25, 2015

Remove comma from number fields in CRM 2011

By default, the Whole Number Format in MSCRM uses the global number format setting and cannot be overridden at the field level.

We can control it via System and User Settings.

System Setting :-
Move to Settings-> Administration-> System Settings-> Format Tab

In the format tab click the Customize button as shown in pic below:


Now all you need to do is change the Digit Grouping Symbol and Digit group.


NOTE: This will change the format for each and every number field in CRM 2011 form including the currency grouping format as well.


But this change will reflect only for new users, but won’t reflect on existing users.
To reflect for the existing users, you need to change user settings.

User Setting :-
Move to File-> Options -> Format Tab

This will open a window as in system settings and you need to follow same steps.

But you cannot log in to all the user accounts. Hence we can update user settings by using following script.

UPDATE [CRMDB].[dbo].[UserSettingsBase]
SET [NumberGroupFormat] = 0


If you don't want to remove comma in all the whole number fields, you can use following javascript to remove the comma in CRM forms.
But this works only for form fields not on views.

document.getElementById("fieldname").value = Xrm.Page.data.entity.attributes.get("fieldname").getValue();

Sunday, July 28, 2013

Popup for SharePoint 2010 Lookups

Normally SharePoint 2010 Lookups open in a new tab.  So if you want to open it as a popup, it is really simple. Add fallowing script to your SharePoint page.

<script type="text/javascript">
var winIsDlg = 0;
(function () {
 var e, q = window.location.search.substring(1), r = /([^&=]+)=([^&]+)/g;
 while (e = r.exec(q))
    if(decodeURIComponent(e[1])=="IsDlg" && decodeURIComponent(e[2]) == "1")
    {winIsDlg=1;}
})();

$(document).ready(function(){
 if(winIsDlg==1)
 {
    $("td[id='SPFieldLookup'] a").each(
      function(){
       this.href="javascript:OpenPopUpPage('" + this.href + "')";
      });
 }
});
</script>

Tuesday, June 11, 2013

Extension Method to Send HTML Emails in SharePoint

/// <summary>
/// </summary>
/// Sends an email to the selected users
/// <param name="web">The web.</param>
/// <param name="from">From.</param>
/// <param name="to">To.</param>
/// <param name="cc">The cc.</param>
/// <param name="bcc">The BCC.</param>
/// <param name="subject">The subject.</param>
/// <param name="body">The body.</param>
/// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
public void SendEmail(SPWeb web, string from, string to, string cc, string bcc, string subject, string body, bool isHtml)
{
    if (!string.IsNullOrEmpty(to))
    {
        var headers = new StringDictionary{
            {"to", to},
            {"subject", subject},
            {"content-type", isHtml ? "text/html" : "text/plain"}
        };

        if (!string.IsNullOrEmpty(from))
        {
            headers.Add("from", from);
        }

        if (!string.IsNullOrEmpty(cc))
        {
            headers.Add("cc", cc);
        }
        if (!string.IsNullOrEmpty(bcc))
        {
            headers.Add("bcc", bcc);
        }

        SPUtility.SendEmail(web, headers, body);
    }
}

Tuesday, December 4, 2012

ERROR - There are no Content Types in the project.

When you are trying to create a new list definition based on a content type that you have defined in your project you are getting this error.

When you have put a SharePoint Project in to a Solution Folder, Visual Studio 2010 loses its ability to locate your SPI’s in your project. The solution you can use to fix this issue is move the project out of the solution folder, add your list and move the project back into the solution folder.

Tuesday, July 10, 2012

Fixing the button disabled issue after download a file in a custom web part in SharePoint2007.

After you download a file from custom web part in a SharePoint 2007 site, normally all the buttons and link buttons are disabled and click events are not working. So here is a simple fix for that. Copy and paste the fallowing script in the bottom of your web part.

<script type="text/javascript">
_spOriginalFormAction = document.forms[0].action;
_spSuppressFormOnSubmitWrapper = true;
</script>

Friday, March 23, 2012

Textbox watermark using jquery

<html>
<head>
<title></title>
<style type="text/css">
.gray
{
color: Gray;
}
.black
{
color: Black;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function () {
$("#txtDate").val("dd/mm/yyyy").addClass("gray");
$("#txtDate").focus(function () {
if ($("#txtDate").val() == "dd/mm/yyyy") {
$("#txtDate").val("").addClass("black").removeClass("gray");
}
});
$("#txtDate").focusout(function () {
if ($("#txtDate").val() == "") {
$("#txtDate").val("dd/mm/yyyy").addClass("gray").removeClass("black");
}
});
});
</script>
</head>
<body>
<input id="txtDate" type="text" />
</body>
</html>

Thursday, March 22, 2012

Convert a file to a byte array

///
/// Function to get byte array from a file
///

/// File name to get byte array
/// Byte Array
public byte[] FileToByteArray(string fileName)
{
byte[] buffer = null;

try
{
// Open file for reading
System.IO.FileStream fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);

// attach filestream to binary reader
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fileStream);

// get total byte length of the file
long totalBytes = new System.IO.FileInfo(fileName).Length;

// read entire file into buffer
buffer = binaryReader.ReadBytes((Int32)totalBytes);

// close file reader
fileStream.Close();
fileStream.Dispose();
binaryReader.Close();
}
catch (Exception exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", exception.ToString());
}

return buffer;
}