Thursday, December 9, 2010

CRM 2011sample java script

Few sample scripts for crm 2011

// Getting the Form Type
Xrm.Page.ui.getFormType()

// Set Focus to a field
Xrm.Page.getControl("fieldname").setFocus(true);


// Setting required Field dynamically
Xrm.Page.getAttribute("fieldname").setRequiredLevel("none");
Xrm.Page.getAttribute("fieldname").setRequiredLevel("required");

Tuesday, November 2, 2010

Dependent Picklist Issue in CRM 2011

To implement Cascading picklist in crm 2011, Add the following piece of code to the first drop down change event


function firstPickListOnChange()
{
  var firstPickListValue = Xrm.Page.getAttribute("new_ddl1").getValue();
    var secondPickListControl = Xrm.Page.ui.controls.get("new_ddl2");
    var secondPickListOptions = secondPickListControl.getAttribute().getOptions();
    secondPickListControl.clearOptions();

switch(firstPickListValue)
  {
     case 100000001:
     secondPickListControl.addOption(secondPickListOptions [0], 0);
     secondPickListControl.addOption(secondPickListOptions [1], 1);
     secondPickListControl.addOption(secondPickListOptions [2], 2);
     break;

     case 100000002:
     secondPickListControl.addOption(secondPickListOptions [3], 0);
     secondPickListControl.addOption(secondPickListOptions [4], 1);
     secondPickListControl.addOption(secondPickListOptions [5], 2);  
     break;
    }
}

updating field/Attribute using crmservice in java script

Here is the process to update field using crmservice

var xml1 = "<?xml version='1.0' encoding='utf-8'?>"+
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
GenerateAuthenticationHeader()+
"<soap:Body>"+
"<Update xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<entity xsi:type='new_entity'>" +
"<new_field1>"+ xmlencode(data) +"</new_field1>" +
"<new_primarykeyfield>" + crmForm.ObjectId + "</new_primarykeyfield>" +
"</entity>"+
"</Update>"+
"</soap:Body>"+
"</soap:Envelope>";
var xHReq1 = new ActiveXObject("Msxml2.XMLHTTP");
xHReq1.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq1.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Update");
xHReq1.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq1.setRequestHeader("Content-Length", xml1.length);
xHReq1.send(xml1);
// Capture the result
var resultXml1 = xHReq1.responseXML;
var errorCount1 = resultXml1.selectNodes('//error').length;


//  Encoding method to replace special characters of the field data

function xmlencode(string) {
    return string.replace(/\&/g,'&'+'amp;').replace(/</g,'&'+'lt;').replace(/>/g,'&'+'gt;').replace(/\'/g,'&'+'apos;').replace(/\"/g,'&'+'quot;');
}

Microsoft Dynamics CRM Pre-Filtering for reports




CRM Pre-Filtering is a very useful option that can be enabled on CRM reports to make them context sensitive and to allow the report to be filtered using the Advanced Find functionality.  Although this is a great feature, it is often an area that is not fully understood which can lead to someone encountering unexpected results.

How is it Enabled?

Automatic Prefiltering (CRMAF_)

There are 2 ways to enable the CRM Pre-Filtering functionality. The easiest option is the CRMAF_ method which simply requires aliasing the filtered views with a name that starts with “CRMAF_”.   A query such as “Select name from FilteredAccount” can simply be changed to “Select name from FilteredAccount as CRMAF_Account”.  Aliasing the Filtered View with a prefix of CRMAF_ will allow CRM to recognize that you would like to enable this entity for pre-filtering.

When you enable the CRM Pre-filtering functionality using the CRMAF_ method, CRM will take a query such as the following and modify it when it is uploaded into CRM:

SELECT name, accountnumber
FROM FilteredAccount as CRMAF_Account

Becomes:

SELECT name, accountnumber
FROM (@P1) as CRMAF_Account

Then CRM will pass a query to the P1 parameter depending on how the report is being filtered. For example: If you are running the report from the Reports area and use the Pre-filtering functionality to filter to only show Accounts that are Active, the resulting query would be something like:

SELECT name, accountnumber
FROM (select FilteredAccount.* from FilteredAccount where statecode = 0) as CRMAF_Account

If you are within a specific Account and run the report, the resulting query would be something like:

SELECT name, accountnumber
FROM (select FilteredAccount.* from FilteredAccount where AccountId = '<CurrentAccountId>') as CRMAF_Account

When you are looking at a list of Accounts with 3 selected and choose the option to run the report against the selected records, the resulting query would be something like:

SELECT name, accountnumber
FROM (select FilteredAccount.* from FilteredAccount where AccountId in ('<1stAccountId>', '<2ndAccountId>', '<3rdAccountId>') as CRMAF_Account

How to find roles of the logged-in user in MS CRM 4.0 using JavaScript

Function returns all the roles of the Current Logged-In User.

function GetCurrentUserRoles()
{
 var xml = "" +
 "" +
 "<soap:envelope xmlns:soap="\"http://schemas.xmlsoap.org/soap/envelope/\"" xmlns:xsi="\"http://www.w3.org/2001/XMLSchema-instance\"" xmlns:xsd="\"http://www.w3.org/2001/XMLSchema\"">" +
 GenerateAuthenticationHeader() +
 " <soap:body>" +
 " <retrievemultiple xmlns="\"http://schemas.microsoft.com/crm/2007/WebServices\"">" +
 " <query xmlns:q1="\"http://schemas.microsoft.com/crm/2006/Query\"" xsi:type="\"Q1:QueryExpression\"">" +
 " <q1:entityname>role</q1:entityname>" +
 " <q1:columnset xsi:type="\"Q1:ColumnSet\"">" +
 " <q1:attributes>" +
 " <q1:attribute>name</q1:attribute>" +
 " </q1:attributes>" +
 " </q1:columnset>" +
 " <q1:distinct>false</q1:distinct>" +
 " <q1:linkentities>" +
 " <q1:linkentity>" +
 " <q1:linkfromattributename>roleid</q1:linkfromattributename>" +
 " <q1:linkfromentityname>role</q1:linkfromentityname>" +
 " <q1:linktoentityname>systemuserroles</q1:linktoentityname>" +
 " <q1:linktoattributename>roleid</q1:linktoattributename>" +
 " <q1:joinoperator>Inner</q1:joinoperator>" +
 " <q1:linkentities>" +
 " <q1:linkentity>" +
 " <q1:linkfromattributename>systemuserid</q1:linkfromattributename>" +
 " <q1:linkfromentityname>systemuserroles</q1:linkfromentityname>" +
 " <q1:linktoentityname>systemuser</q1:linktoentityname>" +
 " <q1:linktoattributename>systemuserid</q1:linktoattributename>" +
 " <q1:joinoperator>Inner</q1:joinoperator>" +
 " <q1:linkcriteria>" +
 " <q1:filteroperator>And</q1:filteroperator>" +
 " <q1:conditions>" +
 " <q1:condition>" +
 " <q1:attributename>systemuserid</q1:attributename>" +
 " <q1:operator>EqualUserId</q1:operator>" +
 " </q1:condition>" +
 " </q1:conditions>" +
 " </q1:linkcriteria>" +
 " </q1:linkentity>" +
 " </q1:linkentities>" +
 " </q1:linkentity>" +
 " </q1:linkentities>" +
 " </query>" +
 " </retrievemultiple>" +
 " </soap:body>" +
 "</soap:envelope>" +
 "";

 var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

 xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
 xmlHttpRequest.setRequestHeader("SOAPAction"," http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
 xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
 xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
 xmlHttpRequest.send(xml);

 var resultXml = xmlHttpRequest.responseXML;
 return(resultXml);
}

Function which calls the above function and search for indivisual role:

function UserHasRole(roleName)
{
 //get Current User Roles, oXml is an object
 var oXml = GetCurrentUserRoles();
 if(oXml != null)
 {
  //select the node text
  var roles = oXml.selectNodes("//BusinessEntity/q1:name");
  if(roles != null)
  {
   for( i = 0; i < roles.length; i++)
   {
    if(roles[i].text == roleName)
    {
     //return true if user has this role
     return true;
    }
   }
  }
 }
 //otherwise return false
 return false;                                              
}

How to use UserHasRole function:

if(UserHasRole(“System Administrator”) == true)
{
           alert(‘User has admin role’);
}
else
{
           alert(‘User does not have admin role’);
}

Friday, August 6, 2010

Hiding Navigation Links & Controls in CRM

Hiding Navigation Links & Controls in CRM

Quick JavaScript solution for hiding both controls on a CRM page and links in the left-hand navigation page on an Entity Form.

The code below provides three functions that can be used to show/hide specific items on a CRM form:

var HIDE = 'none';
var SHOW = 'block';

// Function to show/hide CRM controls on a CRM form
// such as text boxes, lookups, pick-lists etc.
function SetCrmControlVisible(elementName, visibility)
{
SetElementVisible(elementName + '_c', visibility);
SetElementVisible(elementName + '_d', visibility);
}

// Fuction to show/hide specific elements on a CRM form
// such as the left-hand link items (More Addresses, Workflows
// and even custom ISV links
function SetElementVisible(elementId, visibility)
{
var elem = document.getElementById(elementId);
if (elem != null)
{
elem.style.display = visibility;
}
}

// Function to show/hide Navigation "Sections" in the left-hand
// links (Such as Sales, Marketing and Service)
function SetParentElementVisible(elementId, visibility)
{
var elem = document.getElementById(elementId);
if (elem != null && elem.parentElement != null)
{
elem.parentElement.style.display = visibility;
}
}

Add the above code to the Entity OnLoad (and ensure that you enable the event) and after that you are ready to show/hide elements on the CRM form.

By using the IE Developer toolbar, you can retrieve the id of the element to be hidden (note in IE 8 this come built in and is not a seperate download). Open an entity record (in this case a Contact), press CTRL+N to open it in a new window, and then select IE Developer Toolbar.

SetElementVisible('navOpps', HIDE);

To hide the entire “Sales” section from the left-hand navigation pane, I can once again find the id, but this time is of the parent item which would result in the following call to hide it:

SetParentElementVisible('_NA_SFA', HIDE);

Lastly, to hide an element on the form such as the “CRMAttribute” field
      
      SetCrmControlVisible('CRMAttribute', HIDE);

Thursday, August 5, 2010

IntelliSense for Sitemap and ISV.Config Editing in Visual Studio

IntelliSense for Sitemap and ISV.Config Editing in Visual Studio

In CRM we needs to edit Sitemap & ISV.config files most often.
To edit these files easily, visual studio providing intelligence for these XML files.
We have to configure intelligence for the visual studio......


Download the CRM 4.0 SDK. The files you will need are located in the schemas folder of the SDK.
Open the xml(sitemap/isv.config) file in Visual Studio.
Press F4 to bring up the properties dialog.



Copy the following lines into the Schemas value. Keep all as one line and be sure to update your paths to where your files are located:
"D:\CRMSDK 4.0\server\schemas\_root\SiteMapType.xsd"
"D:\CRMSDK 4.0\server\schemas\_resources\customizations.xsd"
"D:\CRMSDK 4.0\server\schemas\_resources\isv.config.xsd"


Now, when you start to edit your file, you will see the IntelliSense for your nodes and any malformed nodes will be highlighted.


Enjoy Editing Sitemap & ISV.config files using intelligence....

Tuesday, August 3, 2010

Using the Advanced Find for FetchXML builder

You can just open the Advanced find page and build the query as you like. Then run the query to see if it returns the data as you wish it should. If you are satisfied with the results and you want to know what query was sent into the CRM Framework, then press F11/ctr+N to get the address bar and enter this script and press enter.

***********************************************
javascript:alert(resultRender.FetchXml.value);
************************************************

If you get a warning about leaving the page, just press 'ok' and then the query which is sent to the framework opens up in a popup. Unfortunately you cannot select the text to copy and paste. But with Windows XP and Windows Server 2003 you can copy all text on the popup by clicking somewhere on the popup (not on the button "OK" ofcourse) and pressing ctrl+c. Now in notepad you can paste the text of the FetchXML.

Try this instead of the alert:

javascript:prompt("my query:", resultRender.FetchXml.value);

Easy way to Insert Huge Number of Values into CRM Picklist

Easily Inserting Huge Number of items into CRM Pick-list ( like Country/State pick-lists)

Follow the Following Steps

1.Create the attribute/picklist in the Microsoft CRM entity customization

2.Add at least one option

3.Export the entity as XML

4.go here: http://www.beatnik.at/picklist_for_mscrm.php

5.Enter the desired picklist values into the textbox

6.Click "Generate XML"

7.Open the XML-File that you exported in step (3) with WordPad or your favourite TextEditor (Notepad tends to have problems with encoding)

8.Search for the displayname or the schemaname of the attribute

9.Replace the options tag with the XML-String generated in (7).
It might look like that:


...


10.Save the XML-Customizations File

11.Import the File into MS CRM and publish

Set Requirement Level for CRM Attributes at Run-time using Java script

Set Requirement Level for CRM Attributes at Run-time using Java script


// Set field to not required
crmForm.SetFieldReqLevel("fieldname", 0);

// Set field to business required
crmForm.SetFieldReqLevel("fieldname", 1);

// Set field to business recommended
crmForm.SetFieldReqLevel("fieldname", 2);

Thursday, June 24, 2010

finding the mime type of the file

=======================================

public string GetMimeType(string fileName)
{
string mimeType;

switch (System.IO.Path.GetExtension(fileName).ToLower())
{
case ".3dm": mimeType = "x-world/x-3dmf"; break;
case ".3dmf": mimeType = "x-world/x-3dmf"; break;
case ".a": mimeType = "application/octet-stream"; break;
case ".aab": mimeType = "application/x-authorware-bin"; break;
case ".aam": mimeType = "application/x-authorware-map"; break;
case ".aas": mimeType = "application/x-authorware-seg"; break;
case ".abc": mimeType = "text/vnd.abc"; break;
case ".acgi": mimeType = "text/html"; break;
case ".afl": mimeType = "video/animaflex"; break;
case ".ai": mimeType = "application/postscript"; break;
case ".aif": mimeType = "audio/aiff"; break;
case ".aifc": mimeType = "audio/aiff"; break;
case ".aiff": mimeType = "audio/aiff"; break;
case ".aim": mimeType = "application/x-aim"; break;
case ".aip": mimeType = "text/x-audiosoft-intra"; break;
case ".ani": mimeType = "application/x-navi-animation"; break;
case ".aos": mimeType = "application/x-nokia-9000-communicator-add-on-software"; break;
case ".aps": mimeType = "application/mime"; break;
case ".arc": mimeType = "application/octet-stream"; break;
case ".arj": mimeType = "application/arj"; break;
case ".art": mimeType = "image/x-jg"; break;
case ".asf": mimeType = "video/x-ms-asf"; break;
case ".asm": mimeType = "text/x-asm"; break;
case ".asp": mimeType = "text/asp"; break;
case ".asx": mimeType = "video/x-ms-asf"; break;
case ".au": mimeType = "audio/basic"; break;
case ".avi": mimeType = "video/avi"; break;
case ".avs": mimeType = "video/avs-video"; break;
case ".bcpio": mimeType = "application/x-bcpio"; break;
case ".bin": mimeType = "application/octet-stream"; break;
case ".bm": mimeType = "image/bmp"; break;
case ".bmp": mimeType = "image/bmp"; break;
case ".boo": mimeType = "application/book"; break;
case ".book": mimeType = "application/book"; break;
case ".boz": mimeType = "application/x-bzip2"; break;
case ".bsh": mimeType = "application/x-bsh"; break;
case ".bz": mimeType = "application/x-bzip"; break;
case ".bz2": mimeType = "application/x-bzip2"; break;
case ".c": mimeType = "text/plain"; break;
case ".c++": mimeType = "text/plain"; break;
case ".cat": mimeType = "application/vnd.ms-pki.seccat"; break;
case ".cc": mimeType = "text/plain"; break;
case ".ccad": mimeType = "application/clariscad"; break;
case ".cco": mimeType = "application/x-cocoa"; break;
case ".cdf": mimeType = "application/cdf"; break;
case ".cer": mimeType = "application/pkix-cert"; break;
case ".cha": mimeType = "application/x-chat"; break;
case ".chat": mimeType = "application/x-chat"; break;
case ".class": mimeType = "application/java"; break;
case ".com": mimeType = "application/octet-stream"; break;
case ".conf": mimeType = "text/plain"; break;
case ".cpio": mimeType = "application/x-cpio"; break;
case ".cpp": mimeType = "text/x-c"; break;
case ".cpt": mimeType = "application/x-cpt"; break;
case ".crl": mimeType = "application/pkcs-crl"; break;
case ".crt": mimeType = "application/pkix-cert"; break;
case ".csh": mimeType = "application/x-csh"; break;
case ".css": mimeType = "text/css"; break;
case ".cxx": mimeType = "text/plain"; break;
case ".dcr": mimeType = "application/x-director"; break;
case ".deepv": mimeType = "application/x-deepv"; break;
case ".def": mimeType = "text/plain"; break;
case ".der": mimeType = "application/x-x509-ca-cert"; break;
case ".dif": mimeType = "video/x-dv"; break;
case ".dir": mimeType = "application/x-director"; break;
case ".dl": mimeType = "video/dl"; break;
case ".doc": mimeType = "application/msword"; break;
case ".dot": mimeType = "application/msword"; break;
case ".dp": mimeType = "application/commonground"; break;
case ".drw": mimeType = "application/drafting"; break;
case ".dump": mimeType = "application/octet-stream"; break;
case ".dv": mimeType = "video/x-dv"; break;
case ".dvi": mimeType = "application/x-dvi"; break;
case ".dwf": mimeType = "model/vnd.dwf"; break;
case ".dwg": mimeType = "image/vnd.dwg"; break;
case ".dxf": mimeType = "image/vnd.dwg"; break;
case ".dxr": mimeType = "application/x-director"; break;
case ".el": mimeType = "text/x-script.elisp"; break;
case ".elc": mimeType = "application/x-elc"; break;
case ".env": mimeType = "application/x-envoy"; break;
case ".eps": mimeType = "application/postscript"; break;
case ".es": mimeType = "application/x-esrehber"; break;
case ".etx": mimeType = "text/x-setext"; break;
case ".evy": mimeType = "application/envoy"; break;
case ".exe": mimeType = "application/octet-stream"; break;
case ".f": mimeType = "text/plain"; break;
case ".f77": mimeType = "text/x-fortran"; break;
case ".f90": mimeType = "text/plain"; break;
case ".fdf": mimeType = "application/vnd.fdf"; break;
case ".fif": mimeType = "image/fif"; break;
case ".fli": mimeType = "video/fli"; break;
case ".flo": mimeType = "image/florian"; break;
case ".flx": mimeType = "text/vnd.fmi.flexstor"; break;
case ".fmf": mimeType = "video/x-atomic3d-feature"; break;
case ".for": mimeType = "text/x-fortran"; break;
case ".fpx": mimeType = "image/vnd.fpx"; break;
case ".frl": mimeType = "application/freeloader"; break;
case ".funk": mimeType = "audio/make"; break;
case ".g": mimeType = "text/plain"; break;
case ".g3": mimeType = "image/g3fax"; break;
case ".gif": mimeType = "image/gif"; break;
case ".gl": mimeType = "video/gl"; break;
case ".gsd": mimeType = "audio/x-gsm"; break;
case ".gsm": mimeType = "audio/x-gsm"; break;
case ".gsp": mimeType = "application/x-gsp"; break;
case ".gss": mimeType = "application/x-gss"; break;
case ".gtar": mimeType = "application/x-gtar"; break;
case ".gz": mimeType = "application/x-gzip"; break;
case ".gzip": mimeType = "application/x-gzip"; break;
case ".h": mimeType = "text/plain"; break;
case ".hdf": mimeType = "application/x-hdf"; break;
case ".help": mimeType = "application/x-helpfile"; break;
case ".hgl": mimeType = "application/vnd.hp-hpgl"; break;
case ".hh": mimeType = "text/plain"; break;
case ".hlb": mimeType = "text/x-script"; break;
case ".hlp": mimeType = "application/hlp"; break;
case ".hpg": mimeType = "application/vnd.hp-hpgl"; break;
case ".hpgl": mimeType = "application/vnd.hp-hpgl"; break;
case ".hqx": mimeType = "application/binhex"; break;
case ".hta": mimeType = "application/hta"; break;
case ".htc": mimeType = "text/x-component"; break;
case ".htm": mimeType = "text/html"; break;
case ".html": mimeType = "text/html"; break;
case ".htmls": mimeType = "text/html"; break;
case ".htt": mimeType = "text/webviewhtml"; break;
case ".htx": mimeType = "text/html"; break;
case ".ice": mimeType = "x-conference/x-cooltalk"; break;
case ".ico": mimeType = "image/x-icon"; break;
case ".idc": mimeType = "text/plain"; break;
case ".ief": mimeType = "image/ief"; break;
case ".iefs": mimeType = "image/ief"; break;
case ".iges": mimeType = "application/iges"; break;
case ".igs": mimeType = "application/iges"; break;
case ".ima": mimeType = "application/x-ima"; break;
case ".imap": mimeType = "application/x-httpd-imap"; break;
case ".inf": mimeType = "application/inf"; break;
case ".ins": mimeType = "application/x-internett-signup"; break;
case ".ip": mimeType = "application/x-ip2"; break;
case ".isu": mimeType = "video/x-isvideo"; break;
case ".it": mimeType = "audio/it"; break;
case ".iv": mimeType = "application/x-inventor"; break;
case ".ivr": mimeType = "i-world/i-vrml"; break;
case ".ivy": mimeType = "application/x-livescreen"; break;
case ".jam": mimeType = "audio/x-jam"; break;
case ".jav": mimeType = "text/plain"; break;
case ".java": mimeType = "text/plain"; break;
case ".jcm": mimeType = "application/x-java-commerce"; break;
case ".jfif": mimeType = "image/jpeg"; break;
case ".jfif-tbnl": mimeType = "image/jpeg"; break;
case ".jpe": mimeType = "image/jpeg"; break;
case ".jpeg": mimeType = "image/jpeg"; break;
case ".jpg": mimeType = "image/jpeg"; break;
case ".jps": mimeType = "image/x-jps"; break;
case ".js": mimeType = "application/x-javascript"; break;
case ".jut": mimeType = "image/jutvision"; break;
case ".kar": mimeType = "audio/midi"; break;
case ".ksh": mimeType = "application/x-ksh"; break;
case ".la": mimeType = "audio/nspaudio"; break;
case ".lam": mimeType = "audio/x-liveaudio"; break;
case ".latex": mimeType = "application/x-latex"; break;
case ".lha": mimeType = "application/octet-stream"; break;
case ".lhx": mimeType = "application/octet-stream"; break;
case ".list": mimeType = "text/plain"; break;
case ".lma": mimeType = "audio/nspaudio"; break;
case ".log": mimeType = "text/plain"; break;
case ".lsp": mimeType = "application/x-lisp"; break;
case ".lst": mimeType = "text/plain"; break;
case ".lsx": mimeType = "text/x-la-asf"; break;
case ".ltx": mimeType = "application/x-latex"; break;
case ".lzh": mimeType = "application/octet-stream"; break;
case ".lzx": mimeType = "application/octet-stream"; break;
case ".m": mimeType = "text/plain"; break;
case ".m1v": mimeType = "video/mpeg"; break;
case ".m2a": mimeType = "audio/mpeg"; break;
case ".m2v": mimeType = "video/mpeg"; break;
case ".m3u": mimeType = "audio/x-mpequrl"; break;
case ".man": mimeType = "application/x-troff-man"; break;
case ".map": mimeType = "application/x-navimap"; break;
case ".mar": mimeType = "text/plain"; break;
case ".mbd": mimeType = "application/mbedlet"; break;
case ".mc$": mimeType = "application/x-magic-cap-package-1.0"; break;
case ".mcd": mimeType = "application/mcad"; break;
case ".mcf": mimeType = "text/mcf"; break;
case ".mcp": mimeType = "application/netmc"; break;
case ".me": mimeType = "application/x-troff-me"; break;
case ".mht": mimeType = "message/rfc822"; break;
case ".mhtml": mimeType = "message/rfc822"; break;
case ".mid": mimeType = "audio/midi"; break;
case ".midi": mimeType = "audio/midi"; break;
case ".mif": mimeType = "application/x-mif"; break;
case ".mime": mimeType = "message/rfc822"; break;
case ".mjf": mimeType = "audio/x-vnd.audioexplosion.mjuicemediafile"; break;
case ".mjpg": mimeType = "video/x-motion-jpeg"; break;
case ".mm": mimeType = "application/base64"; break;
case ".mme": mimeType = "application/base64"; break;
case ".mod": mimeType = "audio/mod"; break;
case ".moov": mimeType = "video/quicktime"; break;
case ".mov": mimeType = "video/quicktime"; break;
case ".movie": mimeType = "video/x-sgi-movie"; break;
case ".mp2": mimeType = "audio/mpeg"; break;
case ".mp3": mimeType = "audio/mpeg"; break;
case ".mpa": mimeType = "audio/mpeg"; break;
case ".mpc": mimeType = "application/x-project"; break;
case ".mpe": mimeType = "video/mpeg"; break;
case ".mpeg": mimeType = "video/mpeg"; break;
case ".mpg": mimeType = "video/mpeg"; break;
case ".mpga": mimeType = "audio/mpeg"; break;
case ".mpp": mimeType = "application/vnd.ms-project"; break;
case ".mpt": mimeType = "application/vnd.ms-project"; break;
case ".mpv": mimeType = "application/vnd.ms-project"; break;
case ".mpx": mimeType = "application/vnd.ms-project"; break;
case ".mrc": mimeType = "application/marc"; break;
case ".ms": mimeType = "application/x-troff-ms"; break;
case ".mv": mimeType = "video/x-sgi-movie"; break;
case ".my": mimeType = "audio/make"; break;
case ".mzz": mimeType = "application/x-vnd.audioexplosion.mzz"; break;
case ".nap": mimeType = "image/naplps"; break;
case ".naplps": mimeType = "image/naplps"; break;
case ".nc": mimeType = "application/x-netcdf"; break;
case ".ncm": mimeType = "application/vnd.nokia.configuration-message"; break;
case ".nif": mimeType = "image/x-niff"; break;
case ".niff": mimeType = "image/x-niff"; break;
case ".nix": mimeType = "application/x-mix-transfer"; break;
case ".nsc": mimeType = "application/x-conference"; break;
case ".nvd": mimeType = "application/x-navidoc"; break;
case ".o": mimeType = "application/octet-stream"; break;
case ".oda": mimeType = "application/oda"; break;
case ".omc": mimeType = "application/x-omc"; break;
case ".omcd": mimeType = "application/x-omcdatamaker"; break;
case ".omcr": mimeType = "application/x-omcregerator"; break;
case ".p": mimeType = "text/x-pascal"; break;
case ".p10": mimeType = "application/pkcs10"; break;
case ".p12": mimeType = "application/pkcs-12"; break;
case ".p7a": mimeType = "application/x-pkcs7-signature"; break;
case ".p7c": mimeType = "application/pkcs7-mime"; break;
case ".p7m": mimeType = "application/pkcs7-mime"; break;
case ".p7r": mimeType = "application/x-pkcs7-certreqresp"; break;
case ".p7s": mimeType = "application/pkcs7-signature"; break;
case ".part": mimeType = "application/pro_eng"; break;
case ".pas": mimeType = "text/pascal"; break;
case ".pbm": mimeType = "image/x-portable-bitmap"; break;
case ".pcl": mimeType = "application/vnd.hp-pcl"; break;
case ".pct": mimeType = "image/x-pict"; break;
case ".pcx": mimeType = "image/x-pcx"; break;
case ".pdb": mimeType = "chemical/x-pdb"; break;
case ".pdf": mimeType = "application/pdf"; break;
case ".pfunk": mimeType = "audio/make"; break;
case ".pgm": mimeType = "image/x-portable-greymap"; break;
case ".pic": mimeType = "image/pict"; break;
case ".pict": mimeType = "image/pict"; break;
case ".pkg": mimeType = "application/x-newton-compatible-pkg"; break;
case ".pko": mimeType = "application/vnd.ms-pki.pko"; break;
case ".pl": mimeType = "text/plain"; break;
case ".plx": mimeType = "application/x-pixclscript"; break;
case ".pm": mimeType = "image/x-xpixmap"; break;
case ".pm4": mimeType = "application/x-pagemaker"; break;
case ".pm5": mimeType = "application/x-pagemaker"; break;
case ".png": mimeType = "image/png"; break;
case ".pnm": mimeType = "application/x-portable-anymap"; break;
case ".pot": mimeType = "application/vnd.ms-powerpoint"; break;
case ".pov": mimeType = "model/x-pov"; break;
case ".ppa": mimeType = "application/vnd.ms-powerpoint"; break;
case ".ppm": mimeType = "image/x-portable-pixmap"; break;
case ".pps": mimeType = "application/vnd.ms-powerpoint"; break;
case ".ppt": mimeType = "application/vnd.ms-powerpoint"; break;
case ".ppz": mimeType = "application/vnd.ms-powerpoint"; break;
case ".pre": mimeType = "application/x-freelance"; break;
case ".prt": mimeType = "application/pro_eng"; break;
case ".ps": mimeType = "application/postscript"; break;
case ".psd": mimeType = "application/octet-stream"; break;
case ".pvu": mimeType = "paleovu/x-pv"; break;
case ".pwz": mimeType = "application/vnd.ms-powerpoint"; break;
case ".py": mimeType = "text/x-script.phyton"; break;
case ".pyc": mimeType = "applicaiton/x-bytecode.python"; break;
case ".qcp": mimeType = "audio/vnd.qcelp"; break;
case ".qd3": mimeType = "x-world/x-3dmf"; break;
case ".qd3d": mimeType = "x-world/x-3dmf"; break;
case ".qif": mimeType = "image/x-quicktime"; break;
case ".qt": mimeType = "video/quicktime"; break;
case ".qtc": mimeType = "video/x-qtc"; break;
case ".qti": mimeType = "image/x-quicktime"; break;
case ".qtif": mimeType = "image/x-quicktime"; break;
case ".ra": mimeType = "audio/x-pn-realaudio"; break;
case ".ram": mimeType = "audio/x-pn-realaudio"; break;
case ".ras": mimeType = "application/x-cmu-raster"; break;
case ".rast": mimeType = "image/cmu-raster"; break;
case ".rexx": mimeType = "text/x-script.rexx"; break;
case ".rf": mimeType = "image/vnd.rn-realflash"; break;
case ".rgb": mimeType = "image/x-rgb"; break;
case ".rm": mimeType = "application/vnd.rn-realmedia"; break;
case ".rmi": mimeType = "audio/mid"; break;
case ".rmm": mimeType = "audio/x-pn-realaudio"; break;
case ".rmp": mimeType = "audio/x-pn-realaudio"; break;
case ".rng": mimeType = "application/ringing-tones"; break;
case ".rnx": mimeType = "application/vnd.rn-realplayer"; break;
case ".roff": mimeType = "application/x-troff"; break;
case ".rp": mimeType = "image/vnd.rn-realpix"; break;
case ".rpm": mimeType = "audio/x-pn-realaudio-plugin"; break;
case ".rt": mimeType = "text/richtext"; break;
case ".rtf": mimeType = "text/richtext"; break;
case ".rtx": mimeType = "text/richtext"; break;
case ".rv": mimeType = "video/vnd.rn-realvideo"; break;
case ".s": mimeType = "text/x-asm"; break;
case ".s3m": mimeType = "audio/s3m"; break;
case ".saveme": mimeType = "application/octet-stream"; break;
case ".sbk": mimeType = "application/x-tbook"; break;
case ".scm": mimeType = "application/x-lotusscreencam"; break;
case ".sdml": mimeType = "text/plain"; break;
case ".sdp": mimeType = "application/sdp"; break;
case ".sdr": mimeType = "application/sounder"; break;
case ".sea": mimeType = "application/sea"; break;
case ".set": mimeType = "application/set"; break;
case ".sgm": mimeType = "text/sgml"; break;
case ".sgml": mimeType = "text/sgml"; break;
case ".sh": mimeType = "application/x-sh"; break;
case ".shar": mimeType = "application/x-shar"; break;
case ".shtml": mimeType = "text/html"; break;
case ".sid": mimeType = "audio/x-psid"; break;
case ".sit": mimeType = "application/x-sit"; break;
case ".skd": mimeType = "application/x-koan"; break;
case ".skm": mimeType = "application/x-koan"; break;
case ".skp": mimeType = "application/x-koan"; break;
case ".skt": mimeType = "application/x-koan"; break;
case ".sl": mimeType = "application/x-seelogo"; break;
case ".smi": mimeType = "application/smil"; break;
case ".smil": mimeType = "application/smil"; break;
case ".snd": mimeType = "audio/basic"; break;
case ".sol": mimeType = "application/solids"; break;
case ".spc": mimeType = "text/x-speech"; break;
case ".spl": mimeType = "application/futuresplash"; break;
case ".spr": mimeType = "application/x-sprite"; break;
case ".sprite": mimeType = "application/x-sprite"; break;
case ".src": mimeType = "application/x-wais-source"; break;
case ".ssi": mimeType = "text/x-server-parsed-html"; break;
case ".ssm": mimeType = "application/streamingmedia"; break;
case ".sst": mimeType = "application/vnd.ms-pki.certstore"; break;
case ".step": mimeType = "application/step"; break;
case ".stl": mimeType = "application/sla"; break;
case ".stp": mimeType = "application/step"; break;
case ".sv4cpio": mimeType = "application/x-sv4cpio"; break;
case ".sv4crc": mimeType = "application/x-sv4crc"; break;
case ".svf": mimeType = "image/vnd.dwg"; break;
case ".svr": mimeType = "application/x-world"; break;
case ".swf": mimeType = "application/x-shockwave-flash"; break;
case ".t": mimeType = "application/x-troff"; break;
case ".talk": mimeType = "text/x-speech"; break;
case ".tar": mimeType = "application/x-tar"; break;
case ".tbk": mimeType = "application/toolbook"; break;
case ".tcl": mimeType = "application/x-tcl"; break;
case ".tcsh": mimeType = "text/x-script.tcsh"; break;
case ".tex": mimeType = "application/x-tex"; break;
case ".texi": mimeType = "application/x-texinfo"; break;
case ".texinfo": mimeType = "application/x-texinfo"; break;
case ".text": mimeType = "text/plain"; break;
case ".tgz": mimeType = "application/x-compressed"; break;
case ".tif": mimeType = "image/tiff"; break;
case ".tiff": mimeType = "image/tiff"; break;
case ".tr": mimeType = "application/x-troff"; break;
case ".tsi": mimeType = "audio/tsp-audio"; break;
case ".tsp": mimeType = "application/dsptype"; break;
case ".tsv": mimeType = "text/tab-separated-values"; break;
case ".turbot": mimeType = "image/florian"; break;
case ".txt": mimeType = "text/plain"; break;
case ".uil": mimeType = "text/x-uil"; break;
case ".uni": mimeType = "text/uri-list"; break;
case ".unis": mimeType = "text/uri-list"; break;
case ".unv": mimeType = "application/i-deas"; break;
case ".uri": mimeType = "text/uri-list"; break;
case ".uris": mimeType = "text/uri-list"; break;
case ".ustar": mimeType = "application/x-ustar"; break;
case ".uu": mimeType = "application/octet-stream"; break;
case ".uue": mimeType = "text/x-uuencode"; break;
case ".vcd": mimeType = "application/x-cdlink"; break;
case ".vcs": mimeType = "text/x-vcalendar"; break;
case ".vda": mimeType = "application/vda"; break;
case ".vdo": mimeType = "video/vdo"; break;
case ".vew": mimeType = "application/groupwise"; break;
case ".viv": mimeType = "video/vivo"; break;
case ".vivo": mimeType = "video/vivo"; break;
case ".vmd": mimeType = "application/vocaltec-media-desc"; break;
case ".vmf": mimeType = "application/vocaltec-media-file"; break;
case ".voc": mimeType = "audio/voc"; break;
case ".vos": mimeType = "video/vosaic"; break;
case ".vox": mimeType = "audio/voxware"; break;
case ".vqe": mimeType = "audio/x-twinvq-plugin"; break;
case ".vqf": mimeType = "audio/x-twinvq"; break;
case ".vql": mimeType = "audio/x-twinvq-plugin"; break;
case ".vrml": mimeType = "application/x-vrml"; break;
case ".vrt": mimeType = "x-world/x-vrt"; break;
case ".vsd": mimeType = "application/x-visio"; break;
case ".vst": mimeType = "application/x-visio"; break;
case ".vsw": mimeType = "application/x-visio"; break;
case ".w60": mimeType = "application/wordperfect6.0"; break;
case ".w61": mimeType = "application/wordperfect6.1"; break;
case ".w6w": mimeType = "application/msword"; break;
case ".wav": mimeType = "audio/wav"; break;
case ".wb1": mimeType = "application/x-qpro"; break;
case ".wbmp": mimeType = "image/vnd.wap.wbmp"; break;
case ".web": mimeType = "application/vnd.xara"; break;
case ".wiz": mimeType = "application/msword"; break;
case ".wk1": mimeType = "application/x-123"; break;
case ".wmf": mimeType = "windows/metafile"; break;
case ".wml": mimeType = "text/vnd.wap.wml"; break;
case ".wmlc": mimeType = "application/vnd.wap.wmlc"; break;
case ".wmls": mimeType = "text/vnd.wap.wmlscript"; break;
case ".wmlsc": mimeType = "application/vnd.wap.wmlscriptc"; break;
case ".word": mimeType = "application/msword"; break;
case ".wp": mimeType = "application/wordperfect"; break;
case ".wp5": mimeType = "application/wordperfect"; break;
case ".wp6": mimeType = "application/wordperfect"; break;
case ".wpd": mimeType = "application/wordperfect"; break;
case ".wq1": mimeType = "application/x-lotus"; break;
case ".wri": mimeType = "application/mswrite"; break;
case ".wrl": mimeType = "application/x-world"; break;
case ".wrz": mimeType = "x-world/x-vrml"; break;
case ".wsc": mimeType = "text/scriplet"; break;
case ".wsrc": mimeType = "application/x-wais-source"; break;
case ".wtk": mimeType = "application/x-wintalk"; break;
case ".xbm": mimeType = "image/x-xbitmap"; break;
case ".xdr": mimeType = "video/x-amt-demorun"; break;
case ".xgz": mimeType = "xgl/drawing"; break;
case ".xif": mimeType = "image/vnd.xiff"; break;
case ".xl": mimeType = "application/excel"; break;
case ".xla": mimeType = "application/vnd.ms-excel"; break;
case ".xlb": mimeType = "application/vnd.ms-excel"; break;
case ".xlc": mimeType = "application/vnd.ms-excel"; break;
case ".xld": mimeType = "application/vnd.ms-excel"; break;
case ".xlk": mimeType = "application/vnd.ms-excel"; break;
case ".xll": mimeType = "application/vnd.ms-excel"; break;
case ".xlm": mimeType = "application/vnd.ms-excel"; break;
case ".xls": mimeType = "application/vnd.ms-excel"; break;
case ".xlt": mimeType = "application/vnd.ms-excel"; break;
case ".xlv": mimeType = "application/vnd.ms-excel"; break;
case ".xlw": mimeType = "application/vnd.ms-excel"; break;
case ".xm": mimeType = "audio/xm"; break;
case ".xml": mimeType = "application/xml"; break;
case ".xmz": mimeType = "xgl/movie"; break;
case ".xpix": mimeType = "application/x-vnd.ls-xpix"; break;
case ".xpm": mimeType = "image/xpm"; break;
case ".x-png": mimeType = "image/png"; break;
case ".xsr": mimeType = "video/x-amt-showrun"; break;
case ".xwd": mimeType = "image/x-xwd"; break;
case ".xyz": mimeType = "chemical/x-pdb"; break;
case ".z": mimeType = "application/x-compressed"; break;
case ".zip": mimeType = "application/zip"; break;
case ".zoo": mimeType = "application/octet-stream"; break;
case ".zsh": mimeType = "text/x-script.zsh"; break;
default: mimeType = "application/octet-stream"; break;
}
return mimeType;
}


---- another way ------
=====================================================================================
public string GetMimeType(string fileName)
{
string mimeType = "application/unknown";
string ext = System.IO.Path.GetExtension(fileName).ToLower();
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (regKey != null && regKey.GetValue("Content Type") != null)
mimeType = regKey.GetValue("Content Type").ToString();
return mimeType;
}

=======================================================================================

Removing max size limit for crm attribute

Just run this sql statement

===========================================
BEGIN TRAN

-- Convert a field to an email body and thus remove the
-- limit check in the platform

UPDATE MetadataSchema.Attribute SET MaxLength = 1073741823,
AttributeLogicalTypeId = 'emailbody' WHERE [name] in ('crmattributeid' )

COMMIT TRAN

==============================================

Triggering ondemand workflow from C# code

// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";

CrmService service = new CrmService();
service.Url = "http://:/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create an ExecuteWorkflow request.
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest();

//Assign the ID of the workflow you want to execute to the request.
request.WorkflowId = new Guid("b050f053-6968-dc11-bb3a-0003ffbad37a");

//Assign the ID of the entity to execute the workflow on to the request.
request.EntityId = new Guid("1DCDEE97-35BB-44BE-8353-58BC36592656");

// Execute the workflow.
ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)service.Execute(request);

Tuesday, March 16, 2010

Solving Issues with opening/Downloading attachments in Notes after Rollup 7

Downloading Notes in MS CRM

        We can download the attachments of Notes by framing the Following URL.
window.open("/MicrosoftCRM/Activities/Attachment/download.aspx?AttachmentType=1001&AttachmentId=4108f5f9-63f7-dd11-b2e0-0003ff2d0264");


     But this approach works only when we don't have roll-up 7 on the system.
After installing the roll-up above 6 , this approach won't works,because security tokens will be added to this link.So it gives error as "INVALID_WRPC_TOKEN"


     so one of the best approach i know to solve this issue is as follows,



public byte[] DownloadAttachment(string AnnotationId)
        {
          
          
            Guid annotationId = new Guid( AnnotationId );

            // Define the columns to retrieve from the annotation record.
            ColumnSet cols1 = new ColumnSet();
            cols1.Attributes = new string[] { "filename", "documentbody" };

            // Retrieve the annotation record.
            annotation annotationAttachment = (annotation)crmService.Retrieve(EntityName.annotation.ToString(), annotationId, cols1);

          
            using (FileStream fileStream = new FileStream(annotationAttachment.filename, FileMode.OpenOrCreate))
            {
                byte[] fileContent = new UTF8Encoding(true).GetBytes(annotationAttachment.documentbody);
            //    fileStream.Write(fileContent, 0, fileContent.Length);

                return fileContent;
            }
          
        }


In the Download Button Click Event,


 byte[] fileData = DownloadAttachment(annotationID);

      
            Response.ClearContent();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
            BinaryWriter bw = new BinaryWriter(Response.OutputStream);
            bw.Write(fileData);
            bw.Close();
            Response.ContentType = mimetype;
            Response.End();

Monday, March 1, 2010

Retrieving appsettings keys & display in drop down list

//Retrieving appsettings keys & display in drop down list
        ArrayList entitylist=new ArrayList();
        Configuration config = WebConfigurationManager.OpenWebConfiguration("~");      


            // Get the appSettings.
            KeyValueConfigurationCollection appSettings =  config.AppSettings.Settings;


           foreach (string key in appSettings.AllKeys)
            {
                       entitylist.Add(appSettings[key].Value);
            }
           ddl_entitylist.DataSource = entitylist;
           ddl_entitylist.DataBind();

Placing a report in the IFrame with GUID as parameter

//Placing a report in the IFrame without asking for credentials

   //get guid of form
var guid= crmFormSubmit.crmFormSubmitId.value;
guid = guid.substring(1, guid.length -1)


var url = "http://server/ReportServer?/Myreport&rs:Command=Render&rc:Toolbar=false&Guid="+ guid;


document.getElementById('IFRAME_Report').src = url;

Calling custom webservice using java script

 //Calling custom web service using java script

var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                var soapXml = "<?xml version='1.0' encoding='utf-8'?>";
                soapXml += "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
                soapXml += "<soap:Body>";
                soapXml += "<GetObjectTypeCode xmlns='http://tempuri.org/'>";
                soapXml += " <Entity>" + entityname + "</Entity>";
                soapXml += " </GetObjectTypeCode>";
                soapXml += " </soap:Body>";
                soapXml += "</soap:Envelope>";


                xmlhttp.open("POST", "/customwebserviceurl.asmx", false);
                xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                xmlhttp.setRequestHeader("Content-Length", soapXml.length);
                xmlhttp.setRequestHeader("SOAPAction", "http://tempuri.org/GetObjectTypeCode");
                xmlhttp.send(soapXml);


                var resultValue = xmlhttp.responseXML.childNodes[1].nodeTypedValue;
                

Sunday, February 21, 2010

checking duplicate detection using custom web service in ms crm 4.0

Here is the web method for duplicate detection web service:


[WebMethod]
public string CheckDuplicateAccount(string objectguid, string name)
{
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
if(objectguid == null || objectguid == string.Empty )
{
//Code for checking account records at creation time
try
{
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.account.ToString();// Create a set of columns to return.
ColumnSet cols = new ColumnSet();
cols.Attributes = new string [] {“name”};// Create the ConditionExpression.
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = “name”;
condition.Values = new string[] {name};// Builds the filter based on the condition
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] {condition};
query.ColumnSet = cols;
query.Criteria = filter;// Retrieve the values from Microsoft CRM.
BusinessEntityCollection retrieved = service.RetrieveMultiple(query);
if(retrieved.BusinessEntities.Length > 0 )
{
return “Duplicate record exists for : ” + name;
}else
{
return “”;
}
}
catch(System.Web.Services.Protocols.SoapException se)
{
return “ERROR: ” + se.Detail.InnerText;
}
}
else {//Code for checking account records at updation time
try{
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.account.ToString();// Create a set of columns to return.
ColumnSet cols = new ColumnSet();
cols.Attributes = new string [] {“name”};// Create the ConditionExpression.
ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = “name”;
condition1.Values = new string[] {name};
condition1.Operator = ConditionOperator.Equal;
ConditionExpression condition2 = new ConditionExpression();
condition2.AttributeName = “accountid”;
condition2.Values = new string[] {objectguid};
condition2.Operator = ConditionOperator.NotEqual;// Builds the filter based on the condition
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] {condition1, ondition2};
query.ColumnSet = cols;
query.Criteria = filter;// Retrieve the values from Microsoft CRM.
BusinessEntityCollection retrieved = service.RetrieveMultiple(query);
if(retrieved.BusinessEntities.Length > 0 )
{
return “Duplicate record exists for : ” + name;
}
else
{
return “”;
}
}catch(System.Web.Services.Protocols.SoapException se)
{
return “ERROR: ” + se.Detail.InnerText;
}
}


call this web method using java script .

Hiding a section using java script in MS CRM 4.0

Hidding a section which contains an IFrame :
var sec = document.getElementById( "tab5"  );
            sec.childNodes[0].rows[ 1 ].style.display = 'none';
           


=======================================================================
Hiding a section with attributes on it :


crmForm.all..parentElement.parentElement.parentElement.style.display='none';



getting the parameters from the current url using java script in MS CRM 4.0

getting the parameters  from the current url using java script:


var id= GetParam(‘id’);


 function GetParam(name) {            
          name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); 
         var regexS = "[\\?&]" + name + "=([^&#]*)";
         var regex = new RegExp(regexS); 
        var results = regex.exec(window.location.href); 
       if (results == null) return ""; 
      else return results[1]; 
  }

changing the background color of a Form & Tab in MS CRM 4.0

use the following Java script on page load event :


document.all.MyForm.style.backgroundColor = '#ccffcc';


document.all.tab0.style.backgroundColor = '#ccffcc';
crmForm.all.tab0Tab.style.backgroundColor='#ccffcc'
document.all.tab1.style.backgroundColor = '#ccffcc';
document.all.tab2.style.backgroundColor = '#ccffcc';
document.all.tab3.style.backgroundColor = '#ccffcc';


change new_label field label style


var field = crmForm.all.new_label_c;
  field.style.fontWeight = 'bold'; // change font to bold
  field.style.fontSize = '12px'; // change font size
  field.style.color = '#ff0000';  //change font color


Adding Custom Button on the Entity Entry part in MS CRM 4.0

Add the following code in the page load Event of Entity.

crmForm.all.sampleattribute.innerHTML = ''<button class='ms-crm-Button' onclick='ButtonClick();'>custom Button</button>'';


crmForm.all.sampleattribute_c.style.display = 'none';



ButtonClick= function() {
alert('alert from custom button click');
}