Tuesday, August 17, 2010

Error while running ISV pages in CRM

If you have a custom application and running as ISV for CRM and you face the below error:


Microsoft.Crm.WebServices.Crm2007.MultipleOrganizationSoapHeaderAuthenticationProvider, Microsoft.Crm.WebServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' doesn't exist


Reason:
The reason for the error is that CRM adds 2 HttpModules (MapOrg and CrmAuthentication) to web.config in the root of the CRM website. The CrmAuthentication HttpModule is in the microsoft.crm.webservices.dll assembly, which is not in the path of the custom virtual directory.

Therefore, you need to deploy the Microsoft.crm.webservices.dll to GAC

Also remove the HttpModule in your web.config

<httpmodules><remove name="CrmAuthentication"></httpmodules>

Tuesday, August 10, 2010

Hide Add Existing Record Button

HideAddExistingRecordButton('account_contacts', 'Add existing Contact to this record');

function HideAddExistingRecordButton(loadAreaId, buttonTitle)
{
var navElement = document.getElementById('nav_' + loadAreaId);
if (navElement != null)
{
navElement.onclick = function LoadAreaOverride()
{
// Call the original method to launch the navigation link
loadArea(loadAreaId);

var associatedViewIFrame = document.getElementById(loadAreaId + 'Frame');
if (associatedViewIFrame != null)
{
associatedViewIFrame.onreadystatechange = function HideTitledButton()
{
if (associatedViewIFrame.readyState == 'complete')
{
var iFrame = frames[window.event.srcElement.id];
var liElements = iFrame.document.getElementsByTagName('li');
for (var i = 0; i < liElements.length; i++)
{
if (liElements[i].getAttribute('title') == buttonTitle)
{
liElements[i].style.display = 'none';
break;
}
}
}
}
}
}
}
}

Thursday, August 5, 2010

Decrease width of field on FORM

Sometime we need to decrease the width of a field on form, say a picklist showing integer 1 to 10. In this kind of field width should be less for a better look.
use :
crmForm.all.field.style.width= '100px';

Account's 360 view in single form for MSCRM 4.0

Account's 360 view in single form for MSCRM 4.0

Normally sales person, call center team, telecallers etc. want evrything to be on single form to avoid multiple click. We may customize Account form to show all customers and their respective activities.





Minimum Dynamics CRM Permissions

Please refer to a good post regarding setting minimun permissions for MSCRM

http://www.orbitone.com/en/blog/archive/2009/10/06/minimum-dynamics-crm-permissions.aspx

This covers the following scenarios:
First login
Create an Activity
Track an Activity in CRM
Send Mail Merge Letters
Create Queck Campaign
Create Reports with Report Wizard
Use Custom Entities
Run Automatic Workflows
Deletion of Records – The Rule and The Exceptions

Even if the above post does not help you, then try the following:
1> Enable Tracing for CRM.
2> Then use Stunnware Tools for Microsoft Dynamics 4.0 to read it in grid form.
3> Check which privilege id is highligted in the error message.
4> In SQL write the query "select name from Privilege where PrivilegeId='GUID' " to get the security role name.
5> Go to security role in MSCRM that the user is having.
6> Provide the permission required.

You may download CRM tools from
http://vidmar.net/weblog/archive/2010/05/06/ultimate-dynamics-crm-tools-list.aspx

Error message received when creating Appointments in MSCRM 4.0

Error message received when creating Appointments in MSCRM 4.0

"You do not have permission to read scheduling information.The system was not able to check availability for this service activity."

However, if you click 'Ignore & save', it will allow you to save the appointment., it will close and save the appointment.

To correct this problem :

>> Open the Security role
>> Click on Business Managment TAB
>> Check that User Setting should have User level write permissions.
>> Go to Service Managment TAB
>> Check under Misc.. that the Search Availablity should have permissions given.

Tuesday, June 29, 2010

crmForm.SetFieldReqLevel throws an error when you try to change the label at runtime and make that field mandatory.

Use the following:

crmForm.all.new_fieldname_c.firstChild.innerText = "New Caption";
crmForm.SetFieldReqLevel("new_fieldname", 2)

Friday, January 15, 2010

10 Common SQL Server Reporting Services Challenges and Solutions

Challenges/Solutions



Original Article at : SSRS
Thanks to Mr. Ryan Duclos

SSRS offers a range of different reporting techniques and technologies, to cater for the reporting needs of all levels of users, from the chief executives, to business analysts, to operational staff. Their reporting needs range from simple, tabular ad-hoc reports, to parameterized, linked or snapshot reports, to complex drill-down and drill-through multi-level reports.


Following is the list of some of the challenges I have encountered while developing such reports using Reporting Services 2000/2005. In the sections that follow, I will cover each challenge individually, providing insight into what may cause the difficulty, alongside a possible solution.



  1. Horizontal Tables: Calendar Reports
  2. Select "ALL" Query Parameter option
  3. Multiple Sheets in Excel
  4. Excel Merged Cell Issues
  5. Blank Pages
  6. Vertical Text
  7. Report Data in Header/Footer
  8. Are you missing XML/CSV data on your exports?
  9. Template Reports
  10. Using the Reporting Services database


A ZIP file containing samples of the reports detailed in this article is available to download , try out and amend to suit your own needs.

Tuesday, January 12, 2010

Convert lead to contact, account and/or opportunity programmatically

public void Convert(Guid leadId, string entityName)
{
SetStateLeadRequest qualifier = new SetStateLeadRequest();
qualifier.EntityId = leadId;
qualifier.LeadState = LeadState.Qualified;
qualifier.LeadStatus = -1;
Service.Execute(qualifier);
//lead is qualified, but not converted to contact yet, if you check the leads from user interface, you will not be able to see this lead in open leads, but you will not see it in contacts.

InitializeFromRequest req = new InitializeFromRequest();
req.EntityMoniker = new Moniker(); // this is the very thing that does the job.
req.EntityMoniker.Id = leadId;
req.EntityMoniker.Name = "lead";
req.TargetEntityName = entityName; //contact for our example req.
req.TargetFieldType = TargetFieldType.All;
InitializeFromResponse rps = (InitializeFromResponse)Service.Execute(req);
//now the lead is converted to a contact, and you can see it in contacts.
Guid entityId = service.Create(rps.Entity);
}

Displaying inactive records in associated view

Below customization is taken from http://ronaldlemmen.blogspot.com/search/label/customization
Thanks to Mr. Ronald.




In some situations you do want to show the inactive records in an associated view as well. My fellow MVP George Doubinski wrote an article about how to solve this by using a plugin:
http://crm.georged.id.au/post/2008/03/07/Displaying-inactive-records-in-associated-view.aspx.

In this post I will show that there are more routes to Rome. I've looked into the option of editing the query which is being executed against CRM. This seemed to be more easy then expected. What I did is:
- Export Customizations for the specific entity
- Open the XML file with a text editor
- Look for the section ""
- Look for the saved query with the localized name of the associated view
- In that saved query look for the filter that is specified in the columnset
- Remove the filter
- Save the Customizations file
- Import the Customizations file
- Publish the Customizations

Here's an example:







....




fullname
createdon
statuscode
subject
leadid
createdon







....


....


....



Keep in mind that you do add the attribute StateCode or StatusCode to the associated view as well, so that end users can see which records are current and which are inactive.

One of the locations that this is useful, is when you are looking into relationships. The out of the box entity does allow you to select party 1, party 2, role 1 and role 2, but no real extensibility options. You could recreate that entity and add useful attributes like startdate and enddate. As soon as the end date has passed, then the record can be deactivated by using workflow. The fact that a person had a professional relationship with a company is information that you do want to keep visible, especially in the associated view.

CRM Javascript: Loop through all elements

var iLen = crmForm.all.length;
for (i = 0; i < iLen; i++)
{
o = crmForm.all[i];
switch (o.tagName)
{
case "INPUT":
case "SELECT":
case "TEXTAREA":
case "IMG":
case "IFRAME":
if (o.id != "leadqualitycode")
{
o.disabled = true;
}
if (o.IsDirty)
{
alert("The value of " + o.name + " has changed.");
}

break;
default:
break;
}
}


More help can be taken from :
http://blogs.infinite-x.net/2007/11/21/disabling-all-fields-on-a-crm-form/

Monday, January 11, 2010

CRM Javascript: Refreshing parent Crm Form

Sometime, it is required to refresh a parent CRM Form from an ASP.Net web page, which is being used as an Iframe application:

private void ReloadWindow()
{
StringBuilder builder = new StringBuilder();
builder.Append(“<script language="JavaScript">”);
builder.Append(“\r\n”);
builder.Append(“if (“);
builder.Append(“(window.opener != null) &&”);
builder.Append(“(window.opener.parent != null) &&”);
builder.Append(“(window.opener.parent.document != null) &&”);
builder.Append(“(window.opener.parent.document.crmForm != null)) {“);
builder.Append(“\r\n”);
builder.Append(“var parentForm = window.opener.parent.document.crmForm;”);
builder.Append(“\r\n”);
builder.Append(“parentForm.Save();”);
builder.Append(“\r\n”);
builder.Append(“window.opener.document.location.replace(window.opener.location);”);
builder.Append(“\r\n”);
builder.Append(“}”);
builder.Append(“\r\n”);
builder.Append(“self.focus();”);
builder.Append(“</script>”);
this.Response.Write(builder.ToString());
}

CRM SDK : Upload/Download an Attachment to Notes

Upload an Attachment
The following code example demonstrates how to upload an attachment to a note programmatically.

// Now create the annotation object.
annotation note = new annotation();
note.notetext = "This is a sample note";
note.subject = "Test Subject";
note.objectid = new Lookup();
note.objectid.type = EntityName.account.ToString();

// Sets the note's parent to the newly created account.
note.objectid.Value = createdAccountId;
note.objecttypecode = new EntityNameReference();
note.objecttypecode.Value = EntityName.account.ToString();

// Create the note.
Guid createdNoteId = service.Create(note);

#region Setup Additional Data Required for this Sample

// Now convert the attachment to be uploaded to Base64 string.
// This will create a doc file in the current folder of executable.
string currentPath = System.Environment.CurrentDirectory.ToString();
TextWriter tw = new StreamWriter(currentPath + "\\Crm" + createdNoteId.ToString() + ".doc");
// Write a line of text to the file.
tw.WriteLine("This document is for testing an attachment upload feature of CRM 4.0.");
tw.Close();

#endregion

// Open a file and read the contents into a byte array.
FileStream stream = File.OpenRead(currentPath + "\\Crm" + createdNoteId.ToString() + ".doc");
byte[] byteData = new byte[stream.Length];
stream.Read(byteData, 0, byteData.Length);
stream.Close();

// Encode the data using base64.
string encodedData = System.Convert.ToBase64String(byteData);

// Now update the note.
annotation updateNote = new annotation();
updateNote.annotationid = new Key();
// Set the Note ID that is being attached to.
updateNote.annotationid.Value = createdNoteId;
updateNote.documentbody = encodedData;
updateNote.filename = "Crm" + createdNoteId.ToString() + ".doc";
updateNote.mimetype = @"application\ms-word";
service.Update(updateNote);



Download an Attachment
The following code example demonstrates how to download an attachment programmatically:


string attachid = "{61BB601D-C43F-4738-BD1F-AD22DC8E7F0E}";
string objecttypecode = "1070"; //SaleLiteratureItem
string url = "http://mycrm/Activities/Attachment/download.aspx?AttachmentType=" + objecttypecode + "&AttachmentId=" + attachid;
System.Net.WebClient myWebClient = new System.Net.WebClient();
myWebClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
myWebClient.DownloadFile(url,"C:\\myfile.txt");