Wednesday, October 27, 2010

Disabling Notes for deactivated records MS CRM

In the OnLoad event:




Code Snippet
/* [s] Disables the creation of new Notes, and editing of existing notes. Attachments can still be opened. */
//If the 'Close' button is showing, means that form Status = Resolved or Cancelled
var btnClose = document.getElementById("_MBwindowclose");
if (btnClose != null)
{
//Need to attachEvent, because IFRAME elements load asynchronously, and elements like 'newNoteButton' are not accessible on form load
var iframe = document.getElementById("notescontrol");
iframe.attachEvent('onreadystatechange', DisableNotes);
}
/* [e] */





The function DisableNotes:




Code Snippet
function DisableNotes()
{
//Hide 'Create a New Note' link
window.frames[0].document.getElementById('newNoteButton').style.visibility="Hidden";
var NotesTable = window.frames[0].document.getElementById('NotesTable');
//Disable the entire table
NotesTable.disabled = true;
var TextArea = NotesTable.getElementsByTagName('TEXTAREA');
//It's still necessary to individually disable the Textareas where users edit the existing notes.
for (i=0;i<TextArea.length;i++)
{
TextArea[i].disabled = true;
}

return;
}

Wednesday, October 20, 2010

Displaying the Number of Notes on the Notes Tab

The Microsoft CRM default form layout displays the Notes section on a separate tab. I often hear complaints from users that they don't know if any notes have been added without first clicking that tab. Many people don't realize that just as with any other section, you can move the Notes section to another tab, just as you would any other section. So one approach that many of our users have liked is to place the Notes section on the first tab as shown below.



This works, but I personally find it annoying as the the cursor will 'jump' down to the Notes section, sometimes scrolling past the info on top set of information, and you have less room to see multiple notes. Since I tend to keep the Notes section on its own separate tab, I wanted to find a way to let users know that data exists on that tab prior to clicking it. I created the following script to display the number of notes on the tab label as shown in the screen shot below.



The script I used is shown below and should be added to the entity's form onLoad function. Since this approach is entirely script based, it should also work on CRM Online. The tab where the Notes section exists must be called Notes for the script to work.
var totalNotes = getTotalNotes(crmForm.ObjectId);
setNoteTabName(totalNotes);
function setNoteTabName(count) {
/* update note tab */
if (crmForm.FormType != 1) {
var cells = document.getElementsByTagName("A");
for (var i = 0; i < cells.length; i++) {
if (cells[i].innerText == "Notes") {
if (count > 0) {
cells[i].innerText = "Notes (" + count + ")";
document.all.crmTabBar.style.width = "auto";
}
break;
}
}
}
}
// Helper method to return the total notes associated with an object
function getTotalNotes(objectId) {
// Define SOAP message
var xml =
[
"<?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>",
"<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>annotation</q1:EntityName>",
"<q1:ColumnSet xsi:type=\"q1:ColumnSet\"><q1:Attributes><q1:Attribute>createdon</q1:Attribute></q1:Attributes></q1:ColumnSet>",
"<q1:Distinct>false</q1:Distinct><q1:Criteria><q1:FilterOperator>And</q1:FilterOperator>",
"<q1:Conditions><q1:Condition><q1:AttributeName>objectid</q1:AttributeName><q1:Operator>Equal</q1:Operator>",
"<q1:Values><q1:Value xsi:type=\"xsd:string\">",
objectId,
"</q1:Value></q1:Values></q1:Condition></q1:Conditions></q1:Criteria>",
"</query>",
"</RetrieveMultiple>",
"</soap:Body>",
"</soap:Envelope>"
].join("");
var resultXml = executeSoapRequest("RetrieveMultiple", xml);
return getMultipleNodeCount(resultXml, "q1:createdon");
}
// Helper method to execute a SOAP request
function executeSoapRequest(action, xml) {
var actionUrl = "http://schemas.microsoft.com/crm/2007/WebServices/";
actionUrl += action;
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", actionUrl);
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
return resultXml;
}
// Helper method to return total # of nodes from XML
function getMultipleNodeCount(tree, el) {
var e = null;
e = tree.getElementsByTagName(el);
return e.length;
}
Naturally, all of the caveats apply...this code is presented as is and may not upgrade with future releases of Microsoft CRM.

Thursday, October 14, 2010

How to get users and primary email address from server database

just execute the below query

DECLARE @DB_Name varchar(100)
DECLARE @Command nvarchar(200)
DECLARE database_cursor CURSOR FOR
SELECT name
FROM master.sys.sysdatabases

OPEN database_cursor

FETCH NEXT FROM database_cursor INTO @DB_Name

WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @Command = 'SELECT SF.fullname, SF.internalemailaddress FROM '+@DB_NAME+'.dbo.systemuserbase SF'
IF @DB_NAME like '%_MSCRM'
EXEC sp_executesql @Command

FETCH NEXT FROM database_cursor INTO @DB_Name
END

CLOSE database_cursor
DEALLOCATE database_cursor


Sudhanshu

Wednesday, October 13, 2010

only showing one typename for lookup

if the lookup is matching to more than one entities and if you want to match to only one entity from a particular lookup just use the following code on onload of the form.

crmForm.all..setAttribute(”lookuptypes”, “2″);


Sudhanshu

Tuesday, October 12, 2010

Change typename in lookup ms crm

i have one challenge as follows, if you can....

on look up, onclick of it a popup window will come, there you can select a record.

there also a picklist will be there(sometimes) where you can also change. the best example is the regarding attribute on letter.

suppose on that picklist i have 3 options as a,b,c.

bydefault a is selected and on basis of some condition i want b to be selected.
its doable and as follows.

just put the following code on load of the form.

crmForm.all..defaulttype = "2";//the number of the picklist value, starts from 1


Sudhanshu

Friday, October 8, 2010

Check which Update Rollup version is installed on your CRM environments



Browse to the CRM website.
Click on the “Help” button on the top right side of the window.
Click on “About Microsoft Dynamics CRM”
Get the build number displayed as follows else the image in side.

Version Build Number Released on
RTM 4.0.7333.3 12/19/2007
Update Rollup 1 4.0.7333.1113 11/24/2008
Update Rollup 2 4.0.7333.1312, 4.0.7333.1316 1/15/2009, 2/8/2009
Update Rollup 3 4.0.7333.1408 3/12/2009
Update Rollup 4 4.0.7333.1551 5/7/2009
Update Rollup 5 4.0.7333.1644, 4.0.7333.1645 7/2/2009
Update Rollup 6 4.0.7333.1750 9/27/2009
Update Rollup 7 4.0.7333.2138 10/22/2009
Update Rollup 8 4.0.7333.2542 12/17/2009
Update Rollup 9 4.0.7333.2644 2/11/2010
Update Rollup 10 4.0.7333.2741 4/8/2010
Update Rollup 11 4.0.7333.2861 6/25/2010
Update Rollup 12 4.0.7333.2935 8/2/2010
Roll up 13 also has been come, will udate that latter.
Sudhanshu

Remotely enable the RDP(mstsc) and restart the system(computer)



Some times while installing CRM or rollups the RDP suddenly stops working.
so enable the rdp and retstart the system remotely follow following steps.

Enable the RDP(mstsc)

From you own system or any other system(it should in the same network)
#1. run and type "regedit"
#2. Click on File, then choose "Connect Network Registry".
#3. In the Select Computer search box either browse Active Directory to locate the remote server, or type its name in the dialog box.
#4. In the remote machine's registry browse to the following key:
HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server

#5. Under the Terminal Server key find the value named fDenyTSConnections (REG_DWORD). Change the value data from 1 (Remote Desktop disabled) to 0 (Remote Desktop enabled). Even if its 0 just change it to 1 and make again to 0.
#6. Reboot the remote machine for the change to take effect. You can easily do so by opening a command prompt and typing the following command:

Restart the system remotely
#1. Start -> Run and type shutdown -i
This window will show up. Press Add and type either IP or DNS of remote server.

Select shutdown or restart and press OK. That 's it. For your convenience you may run from command line constanct ping (ping servername -t) when the server actually stopped to respond to pings and when it started again.

#2. Alternatively you can go to command prompt (start -> run -> cmd) on your workstation and Type
shutdown -r -m \\x.x.x.x
Replace x.x.x.x with the IP address or computer name of the remote machine. -r option is for restart, don't use -r if want to just shut down the system

so be carefull about the input parameter -r

Have fun
Sudhanshu

Thursday, October 7, 2010

Disable the Links in a Lookup Field MS CRM 4.0

Sometimes simply making a Lookup field “read only” isn’t enough. Sometimes, you may want to restrict the ability to even follow the links held inside the field. so this is here how to handel that from the user.

//this a general function which takes the name of the lookup

function DisableLookupLinks(lookupFieldName) {
var lookupParentNode = document.getElementById(lookupFieldName + "_d");
var lookupSpanNodes = lookupParentNode.getElementsByTagName("SPAN");

for (var spanIndex = 0; spanIndex < lookupSpanNodes.length; spanIndex ++) {
var currentSpan = lookupSpanNodes[spanIndex];

currentSpan.onclick = function() {};
}
}

now To disable a field's Lookup links, pass the field's schema name into the function.
DisableLookupLinks("<lookupfield_name>");

Sudhanshu

Extreme Fast AsyncOperations MS CRM 4.0

This white paper from MS might be more applicable to you.

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=e76d8916-81a6-4330-90ae-b24f8263fff8&DisplayLang=en

CRM Configuration Changes

These configurations were done so that the workflow service would pick up the workflows as fast as it can and would not create a backlog of workflows and overload the workflows stack. Changes were made in the MSCRM_CONFIG database, on the dbo.DeploymentProperties table.


Parameters that were changed:



•AsyncSelectInterval
•Default value: 5
•New value: 1

•AsyncStateStatusUpdateInterval
•Default value: 5
•New value: 1

•AsyncItemsInMemoryLow
•Default value: 1000
•New value: 10

•AsyncItemsInMemoryHigh
•Default value: 2000
•New value: 20

Sudhanshu

Wednesday, October 6, 2010

set the time in the time picker in MS CRM Date time field

Hi all,

some times we need the exact time , while some body is picking the date from the date picker. and the attribute is of date and time and showing full date and time also.
So once the user selects the date the time goes to 12:00 AM.
if (s)he wats to get the current time then just follow the followings

#1 get the selected date values by user

var selectedDate = crmForm.all.<datefieldname>.DataValue;
var date = selectedDate.getDate();
var month = selectedDate.getMonth();
var year = selectedDate.getYear();

#2 create the client date and fetch the time values

var clientDate = new Date();
var hr = clientDate .getHours();
var mnt = clientDate .getMinutes();
var sec = clientDate .getSeconds();

//change the value to hr and min
if(mnt >= 0 && mnt <=30){
hr = hr; // no change
mnt = 30; //make the mnt to 30
}
if(mnt > 30 && mnt <=59){
hr = hr+1; // add 1 to hr to round up
mnt = 0; // reset the mnt
}


#3 now create a new date with the year,month,date from the selected date and the hour,minutes,seconds from the client time

var finalDate = new Date(year,month,date,hr,mnt,sec);
//alert(finalDate);

#4 finally assing the time to the destination


crmForm.all.<datefieldname>.DataValue = finalDate;

Sudhanshu

Tuesday, October 5, 2010

Enable CRM 4.0 URL QueryString Parameter Passing…

Sometimes we need to pass some parameters and values the URL as querystring.
and it will not work due to some reason.
to make it happen follow the following steps.

open the regedit
Create a DWORD registry key named [DisableParameterFilter] under [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM], set the value to 1 , and the do a iisreset, this enable the url querystring parameter passing under CRM 4.

Sudhanshu