Selecting a random record from Table/View. Assuming the table name is Contact:
SELECT TOP 1 * FROM Contact ORDER BY NEWID()
GO
Tuesday, October 24, 2006
SQL: Select a random record
Tuesday, September 19, 2006
MSCRM 3.0 Client: Hiding Tab, Menu Item and Button
try { var objElement = document.getElementById("tab3Tab"); objElement.style.display = 'none'; } catch(ERR) {}
To hide a Menu Item or Button, find out the Element ID, and attach codes below to form OnLoad event:
try { // Hiding "Recalculate" Menu Item var objElement = document.getElementById("_MIcrmFormSubmitCrmForm1truetruefalse"); objElement.style.display = 'none'; } catch(ERR) {}
try { // Hiding "Recalculate" Button var objElement = document.getElementById("_MBcrmFormSubmitCrmForm1truetruefalse"); objElement.style.display = 'none'; } catch(ERR) {}
Usually Menu Item will be prefixed with _MI... and button will be prefixed with _MB...
The same method can be used to hide an item from the left Navigation Pane.
Wednesday, August 02, 2006
MSCRM 3.0 SDK: Close Opportunity
To close a Won Opportunity:
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
WhoAmIRequest req = new WhoAmIRequest();
WhoAmIResponse res = (WhoAmIResponse) service.Execute(req);
Guid OpportunityID = new Guid("{e0fbb411-cb35-db11-b3d2-0003ffc41bcc}");
// Close Opportunity - Won
WinOpportunityRequest wReq = new WinOpportunityRequest();
opportunityclose won = new opportunityclose();
// Oppoturnity ID
Guid id = new Guid(OpportunityID);
Lookup oLookup = new Lookup();
oLookup.Value = id;
won.opportunityid = oLookup;
// Status Reason
Status oStatus = new Status();
oStatus.Value = 3; // Won
won.statuscode = oStatus;
// Execute Request
wReq.OpportunityClose = won;
wReq.Status = 3; // Won
WinOpportunityResponse wRes = (WinOpportunityResponse) service.Execute(wReq);
Lost Opportunity:
// Opportunity - Lost
LoseOpportunityRequest lReq = new LoseOpportunityRequest();
opportunityclose lose = new opportunityclose();
// Oppoturnity ID
Guid id = new Guid(strOpportunityID);
Lookup oLookup = new Lookup();
oLookup.Value = id;
lose.opportunityid = oLookup;
// Status Reason
Status oStatus = new Status();
oStatus.Value = 5; // Out-Sold
lose.statuscode = oStatus;
// Execute Request
lReq.OpportunityClose = lose;
lReq.Status = 5; // Out-Sold
LoseOpportunityResponse lRes = (LoseOpportunityResponse) service.Execute(lReq);
Wednesday, July 26, 2006
SQL Server: Change Server Name
Run following command to change the server name in sys.servers system
table:
sp_dropserver @server = 'old_server_name'
GO
sp_addserver @server = 'new_server_name', @local = 'local'
GO
Restart the server, and use command below to verify:
SELECT @@SERVERNAME
or execute command below (for SQL 2005):
C:\>sqlcmd -A
UPDATE sys.servers SET name = 'new_server_name'
GO