Friday, April 19, 2013

Microsoft CRM Services



What is a web service in Microsoft CRM?
A web service is a programming interface exposed by an application. It follows industry standards that allow it to be consumed ( used ) by any software technology that understands the web service standards defined by W3C.
CRM Live exposes two web services: CrmService & CrmMetadataService
CrmService is used to fetch data, set data, make programmatic configuration changes, etc.
CrmMetadataService is used to query about the metadata. The metadata describes the entities, attributes, relationships, and so on, of the organization.
The WSDL, which stands for web service description language, can be fetched from your CRM system via the Settings-Download WSDL. You use this to create your web reference’s.
The endpoint URL for each of these in an internet facing deployment of CRM can be discovered thru the CrmDiscoveryService Web Service. You’ll also use the CrmDiscoveryService  for policy information during the authentication process. 
The reference for the discovery service is at
https://MyOrgName/MSCRMServices/2007/Passport/CrmDiscoveryService.asmx
Then in your code set the URL for the CrmService and CrmMetadataService using the endpoint returned from the discovery services. The URLs can be retrieved from your ticket response object.

Example :
// STEP 1: Retrieve a policy from the Discovery Web service.
CrmDiscoveryService discoveryService = new CrmDiscoveryService();
discoveryService.Url = String.Format("https://{0}/MSCRMServices/2007/Passport/CrmDiscoveryService.asmx",_hostname);
RetrievePolicyRequest policyRequest = new RetrievePolicyRequest();
RetrievePolicyResponse policyResponse = (RetrievePolicyResponse)discoveryService.Execute(policyRequest);
// STEP 2: Retrieve a Passport ticket from the Passport service.
LogonManager lm = new LogonManager();
string passportTicket = lm.Logon(UserID, Password, _partner, policyResponse.Policy, _environment);
// STEP 3: Retrieve a CrmTicket from the Discovery Web service.
RetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();
crmTicketRequest.OrganizationName = _organization;
crmTicketRequest.PassportTicket = passportTicket;
RetrieveCrmTicketResponse crmTicketResponse = (RetrieveCrmTicketResponse)discoveryService.Execute(crmTicketRequest);
// STEP 4: Create and configure an instance of the CrmService Web service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = AuthenticationType.Passport;
token.CrmTicket = crmTicketResponse.CrmTicket;
token.OrganizationName = crmTicketResponse.OrganizationDetail.OrganizationName;
CrmService crmService = new CrmService();
crmService.Url = crmService.CrmAuthenticationTokenValue = token;
// STEP 5: Invoke the desired CrmService Web service methods.
lead newlead = new lead();
newlead.description = "Lead Test";
newlead.subject   = "My Lead";
newlead.firstname ="Sai";
newlead.lastname  = "Krishna";


// Call the Create method to create an lead
Guid leadID = crmService.Create(newlead);
When using the CRM Web Services, there are times when you need to work with custom entities that aren't described in the current WSDL that you have. The DynamicEntity lets you program against types that you don't have the full description in the WSDL. This can be very helpful when you don't have access to fetch the systems current WSDL files.
Let's look at a code snippet to do this.

Here at the steps .
1. Create all the attribute values
2. Create Dynamic Entity
3. Set the attribute properties
4. Create the Target
5. Execute the Request
I'll show how to create a Customer entity and associate an existing account id to the new entity. The CRM SDK support a variety of property type objects. Be sure to use the correct object type with the definition of the attribute. Mismatching this is a common error. I'll save you some time with this tip: Use LookUpProperty instead of Guid type when relating entities together. Even though the value you set will be a GUID, it only works with the LookupProperty object.
// Create Properties
LookupProperty accountid = new LookupProperty();
accountid.Name = "new_accountid";
accountid.Value = new Lookup();
accountid.Value.Value = new Guid("260FB27F-25E6-DC11-BEDA-0013210AC0BE");
accountid.Value.type = EntityName.account.ToString();

StringProperty name = new StringProperty();
name.Name = "new_CustomerName";
name.Value = "Krishna";
DateTime userTime = new DateTime();
userTime = dtExpDate;

CrmService.CrmDateTime LaunchDate = new CrmService.CrmDateTime();
LaunchDate.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:s}", userTime);
CrmDateTimeProperty LaunchDate = new CrmDateTimeProperty();
LaunchDate.Name = "new_LaunchDate";
LaunchDate.Value = LaunchDate;

// Create the DynamicEntity object.
DynamicEntity AcmeEntity = new DynamicEntity();

// Set the name of the entity type.
AcmeEntity.Name = "new_Customer";

// Set the properties
KeyEntity.Properties = new Property[] { name, accountid, LaunchDate };

// Create the target.
TargetCreateDynamic targetCreate = new TargetCreateDynamic();
targetCreate.Entity = KeyEntity;

// Create the request object.
CreateRequest create = new CreateRequest();

// Set the properties of the request object.
create.Target = targetCreate;

// Execute the request.
CreateResponse created = (CreateResponse)crmService.Execute(create); 

That's it. Now we have an instance of the entity type
new_Customer that is related to the account id. Don't forget to check out the SDK for complete samples and descriptions of all the property objects.  Also, if you get errors, the first to check is that the attribute type matches the property object that you are using.

Wednesday, April 17, 2013

Automatic flow for Visits in CRM

Since workflow normally waits for a future date so let me give you a simple solution for this.
- Create a custom field at contact named next Visit
- Create two workflows:

#1 Update Next Visit (This workflow sets the next Visit first time and will not execute thereafter)
Fire this workflow on create of contact/account or on change of Visit field.
If Visit contains data Then
Update Contact Next Visit Field by adding 3 Months in Visit field

2) Birthday Reminder (This workflow sends reminder emails and updates Next Visit Field after each execution by adding 3 months)
If Next Visit contains data Then
Wait untill 5 days Before Visit
Send Email reminder to user - Receptionist
Update Next Visit= After 3 months of Current Visit

Calling external JS files from MS CRM 4.0 form

function LoadFunction() { }
//create a Script loader object + function to be called when the script has
//finished loading
window.ScriptLibrary = new ScriptLoader(LoadFunction);
//url , false - cache, true - no cache
ScriptLibrary.Load('//FileName.js', true); 


Another Example:
//create the function which will load the file
function LoadExternalScript(scriptFile)
{
var netRequest = new ActiveXObject("Msxml2.XMLHTTP");
netRequest.open("GET", scriptFile, false);
netRequest.send(null);
eval(netRequest.responseText);
}

//call the above function by passing your file name(absolute path)
LoadExternalScript("/ISV/js/filename.js");
//now call the OnLoad function, which has defined in the external JS file
//also you can define and call other function, in the external JS files
OnLoad();

Wednesday, March 6, 2013

Step by step: Installing CRM 2011 On-premise and Migrating from Dynamics CRM 4.0 (32 bits, on-premise).

click here/here for step by step: Installing CRM 2011 On-premise and Migrating from Dynamics CRM 4.0 (32 bits, on-premise).

click here for detailed explaination.

Wednesday, February 27, 2013

Change the sa password in SQL Server

Login into SQL Server using Windows Authentication.
In Object Explorer, open Security folder, open Logins folder. Right Click on SA account and go to Properties.

The Simple trick is to check the box “Map to credential” as shown below after providing a new password and click Okay.

SQL Server 2008 Designer Behavior Change: Saving Changes Not Permitted

The Save (Not Permitted) dialog box warns you that saving changes is not permitted because the changes you have made require the listed tables to be dropped and re-created.
The following actions might require a table to be re-created:
  • Dropping a column
  • Changing column nullability
  • Changing the order of the columns
  • Changing the data type of a column
To change this option, on the Tools menu, click Options, expand Designers, and then click Table and Database Designers. Select or clear the Prevent saving changes that require the table to be re-created check box.

Friday, February 15, 2013

Check the Microsoft Certification

Use the below link to Check/Share the Microsoft Certication Details
https://mcp.microsoft.com/authenticate/validatemcp.aspx
use the Transcript ID and access code as your password
You are now ready to share your qualifications with your employer, friends, and colleagues. 
Provide them with your Transcript ID and the Access Code, and direct them to https://mcp.microsoft.com/authenticate/validatemcp.aspx. Remember, you can change your Access Code at any time. 
If you decide to stop sharing your transcript, simply change your Access Code at https://mcp.microsoft.com/mcp/tools/MCPDirectoryPreferences.aspx and refrain from sharing the new Access Code with anyone.

The below link is used to update your Certification details 
https://www.microsoft.com/learning/members/en/us/mcp/mcp-default.aspx