Friday, May 10, 2013

Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive

I'm trying to up load my site and I'm getting this error message:
    Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.

<compilation debug="true" targetFramework="4.0">

The site works fine on my local pc but won't open when I loaded it to my host at tried to view it on line.

Registering the framework with IIS is what worked for me:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -i
Type the above statement in command prompt

Wednesday, May 1, 2013

CRM 2011 JScript Syntaxes

XRM Page Model.

The Xrm.Page object serves as a namespace object to consolidate three properties on the form:

Xrm.Page.context
Xrm.Page.context provides methods to retrieve information specific to an organization, a user, or parameters that were passed to the form in a query string.

Xrm.Page.data.entity

Xrm.Page.data provides an entity object that provides collections and methods to manage data within the entity form.

Xrm.Page.ui
Xrm.Page.ui provides collections and methods to manage the user interface of the form.




CRM Enity Properties
  •  Xrm.Page.data.entity.getEntityName()   //Entity Name
  •  Xrm.Page.data.entity.getId()                     //Record GUID
  •  Xrm.Page.ui.getFormType()                      //CRM Form Type (Integer)
    **Create (1), Update (2), Read Only (3), Disabled (4), Bulk Edit (6)
Get & Set Text Field
  • Xrm.Page.data.entity.attributes.get(“fld_name”).getValue()
  • Xrm.Page.data.entity.attributes.get(“fld_name”).setValue(“First”)
Get Lookup
  •      Xrm.Page.data.entity.attributes.get(“primarycontactid”)
  •     Xrm.Page.data.entity.attributes.get(“primarycontactid”).getValue()[0].id
  •     Xrm.Page.data.entity.attributes.get(“primarycontactid”).getValue()[0].name
Set Lookup
  •  var lookUpValue = new Array();
    lookUpValue[0] = new Object();
    lookUpValue[0].id = idValue;
    lookUpValue[0].name = textValue;
    lookUpValue[0].entityType = ‘{Entity_Name}’;
  • Xrm.Page.getAttribute(“primarycontactid”).setValue(lookUpValue);
Option Set Properties
  •  Xrm.Page.data.entity.attributes.get(“new_country”)
  • Xrm.Page.data.entity.attributes.get(“new_country”).getOptions()   // All Options
  •  Xrm.Page.data.entity.attributes.get(“new_country”).getText()         // Option Label value
  •  Xrm.Page.data.entity.attributes.get(“new_country”).getValue()       // Selected option value
Hide/Show controls
  • Xrm.Page.ui.controls.get(“name”).setVisible(true/false)
Disable/Enable controls
  •  Xrm.Page.ui.controls.get(“name”).setDisabled(true/false)
Set Focus
  • Xrm.Page.ui.controls.get(“name”).setFocus();
Set field’s Requirement Level
  • Xrm.Page.getAttribute(“name”).setRequiredLevel(“none”);
  • Xrm.Page.getAttribute(“name”).setRequiredLevel(“required”);
  •  Xrm.Page.getAttribute(“name”).setRequiredLevel(“recommended”);
Set the label for the control
  •  Xrm.Page.ui.controls.get(“name”).setLabel(“Label Text”);
Set URL for IFrams/WebResource
  •  Xrm.Page.ui.controls.get(“IFrame/WebResource Name”).setSrc(“URL”);
Get Parent of current control
  •  Xrm.Page.ui.controls.get(“name”).getParent();
“Current User” & “Organization” details
  • Xrm.Page.context.getUserId()                     //Current User ID
  •  Xrm.Page.context.getOrgUniqueName() //Organization Name
  •  Xrm.Page.context.getServerUrl()              //Server URL
  •  Xrm.Page.context.getUserRoles()             //Role ID’s of current user
Check isDirty
  • Xrm.Page.data.entity.getIsDirty()  // Form is IsDirty
  • Xrm.Page.data.entity.attributes.get(“new_name”).getIsDirty()  //Field is IsDirty
Save Form
  • function save(){Xrm.Page.data.entity.save();}
Save&close Form
  • function saveandclose(){Xrm.Page.data.entity.save(“saveandclose”);}
Close Form
  • function close(){Xrm.Page.ui.close();}
Expand/Collapse Tabs
  • var myTab = Xrm.Page.ui.tabs.get(“{tab_name}”);
  • myTab.setDisplayState(“expanded”); // To expand tab
  • myTab.setDisplayState(“collapsed”); // To collapse tab
Hide/Show Tabs & Sections
  • var myTab = Xrm.Page.ui.tabs.get(“{tab_name}”);
  • myTab.setVisible(True/False);
  • var mySec = myTab.sections.get(“{sec_name}”);
  • mySec.setVisible(True/False);

Tuesday, April 30, 2013

Dynamics CRM 2011 - Trigger a workflow from JavaScript

Recently I had a requirement to trigger a workflow on click of ribbon button when it meets certain criteria. Refer below link for calling JavaScript function from custom ribbon button.
http://ankit.inkeysolutions.com/2012/01/crm-2011-how-to-use-visual-ribbon.html
The criteria values are checked using JavaScript and if all criteria are satisfied then the workflow is to be triggered. The function below will take two inputs where entityId is the id of the record for which the workflow will execute and workflowProcessId is the id of the workflow which we want to execute. 




function startWorkflow(entityId, workflowProcessId) {
  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\">" +  Xrm.Page.context.getAuthenticationHeader() +  "<soap:Body>" +"<Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +"<Request xsi:type=\"ExecuteWorkflowRequest\">" +"<EntityId>" + entityId + "</EntityId>" +  "<WorkflowId>" + workflowProcessId + "</WorkflowId>" + "</Request>" +"</Execute>" +"</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/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
  xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
  xmlHttpRequest.send(xml);
}
 

How to retrieve the Selected Record Ids of a Sub Grid in CRM 2011 using javascript

Retrieve the Selected Record Ids of a Sub Grid in CRM 2011 using javascript
Code Snippet:
var gridControl = document.getElementById("yourSubGridName").control;
var ids = gridControl.get_selectedIds();

Thursday, April 25, 2013

CRM Field Masking with JQuery

It’s always a good thing to make the user experience as nice as possible. One thing missing from CRM is the ability to mask fields. You’ve probably seen this online on sites that ask for your phone number or social security number where the text box already contains the hyphens in the necessary spots. This clues the user in as to what format you’re expecting from them and leads to cleaner data.
Recently I had a client that needed all their zip codes to be entered along with the carrier code, which is the 4 number suffix at the end of a zip code. I figured this would be a great opportunity to implement some field masking.
Using a JQuery masking plugin written by Josh Bush. I was able to add a single line function to define my masking. To do the same, download and upload it to your CRM system as a web resource.
Next, jump onto the form that you want to add a field mask to and add the JQuery and JQuery Mask library.

sc_jquery1.6.2.min
sc_Jquery_mask
sc_global

A list of the necessary libraries
You’ll also notice that I have my own Global javascript file in the list. This file contains a reference to a Mask function that will call the JQuery Mask plugin. You can choose to register each field mask function call individually or you can place them all on a single function. I’ve shown both examples below.

function Mask(field, format)
{   
$("#"+field).mask(format);
}

function maskFields()
{
Mask("address1_postalcode", "99999-9999");
Mask("telephone1", "(999) 999-9999");
Mask("telephone2", "(999) 999-9999");
Mask("fax", "(999) 999-9999");
}

The next step is to define an OnLoad function call. We’ll be calling the Mask function above and passing it in the schema name of the field and the mask value we want applied.
Finally, the function call
You’ll also need to register one more function call on the OnSave. The reason for this is that the JQuery plugin doesn’t save the value to the CRM form. We need to take care of this. We do this by comparing the value in the html to the value on the field. If they’re different, then this means the user changed the field. Insert the following into your global and register it in the OnSave.
function formatFields(){  

formatField("address1_postalcode");           
formatField("fax");           
formatField("telephone1");           
formatField("telephone2");
}
function formatField(fieldName){           
if(Xrm.Page.getAttribute(fieldName).getValue() != $("#"+fieldName).val())                       
Xrm.Page.getAttribute(fieldName).setValue($("#"+fieldName).val());
}
And that’s all there is to it. Here are the results.
The JQuery plugin allows us to define all sorts of field masks and you can add dynamic logic to change the mask based on the country. Happy CRMing!
UPDATE:
To get optional formatting, take a look at examples on the jquery plugin page:
http://digitalbush.com/projects/masked-input-plugin/
Refer http://taoofcrm.com/2011/05/19/crm-field-masking-with-jquery/

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.